Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

up

Manav Rathi84dda89e1553
diff --git a/web/packages/gallery/services/upload/remote.ts b/web/packages/gallery/services/upload/remote.ts
index 71b51ad3bf..3cbbf0892d 100644
--- a/web/packages/gallery/services/upload/remote.ts
+++ b/web/packages/gallery/services/upload/remote.ts
@@ -40,6 +40,44 @@ export type ObjectUploadURL = z.infer<typeof ObjectUploadURL>;
const ObjectUploadURLResponse = z.object({ urls: ObjectUploadURL.array() });
+/**
+ * Fetch a fresh list of URLs from remote that can be used to upload files
+ * and thumbnails to.
+ *
+ * @param countHint An approximate number of files that we're expecting to
+ * upload.
+ *
+ * @returns A list of pre-signed object URLs that can be used to upload data
+ * to the S3 bucket.
+ */
+export const fetchUploadURLs = async (countHint: number) => {
+ const count = Math.min(50, countHint * 2).toString();
+ const params = new URLSearchParams({ count });
+ const url = await apiURL("/files/upload-urls");
+ const res = await fetch(`${url}?${params.toString()}`, {
+ headers: await authenticatedRequestHeaders(),
+ });
+ ensureOk(res);
+ return ObjectUploadURLResponse.parse(await res.json()).urls;
+};
+
+/**
+ * Sibling of {@link fetchUploadURLs} for public albums.
+ */
+export const fetchPublicAlbumsUploadURLs = async (
+ countHint: number,
+ credentials: PublicAlbumsCredentials,
+) => {
+ const count = Math.min(50, countHint * 2).toString();
+ const params = new URLSearchParams({ count });
+ const url = await apiURL("/public-collection/upload-urls");
+ const res = await fetch(`${url}?${params.toString()}`, {
+ headers: authenticatedPublicAlbumsRequestHeaders(credentials),
+ });
+ ensureOk(res);
+ return ObjectUploadURLResponse.parse(await res.json()).urls;
+};
+
/**
* Lowest layer for file upload related HTTP operations when we're running in
* the context of the photos app.
@@ -67,27 +105,6 @@ export class PhotosUploadHTTPClient {
}
}
- /**
- * Fetch a fresh list of URLs from remote that can be used to upload files
- * and thumbnails to.
- *
- * @param countHint An approximate number of files that we're expecting to
- * upload.
- *
- * @returns A list of pre-signed object URLs that can be used to upload data
- * to the S3 bucket.
- */
- async fetchUploadURLs(countHint: number) {
- const count = Math.min(50, countHint * 2).toString();
- const params = new URLSearchParams({ count });
- const url = await apiURL("/files/upload-urls");
- const res = await fetch(`${url}?${params.toString()}`, {
- headers: await authenticatedRequestHeaders(),
- });
- ensureOk(res);
- return ObjectUploadURLResponse.parse(await res.json()).urls;
- }
-
async fetchMultipartUploadURLs(
count: number,
): Promise<MultipartUploadURLs> {
@@ -400,23 +417,6 @@ export class PublicAlbumsUploadHTTPClient {
}
}
- /**
- * Sibling of {@link fetchUploadURLs} for public albums.
- */
- async fetchUploadURLs(
- countHint: number,
- credentials: PublicAlbumsCredentials,
- ) {
- const count = Math.min(50, countHint * 2).toString();
- const params = new URLSearchParams({ count });
- const url = await apiURL("/public-collection/upload-urls");
- const res = await fetch(`${url}?${params.toString()}`, {
- headers: authenticatedPublicAlbumsRequestHeaders(credentials),
- });
- ensureOk(res);
- return ObjectUploadURLResponse.parse(await res.json()).urls;
- }
-
async fetchMultipartUploadURLs(
count: number,
credentials: PublicAlbumsCredentials,
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index 112d2913b5..417e0b2bf8 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -59,6 +59,8 @@ import { tryParseEpochMicrosecondsFromFileName } from "./date";
import {
completeMultipartUpload,
completeMultipartUploadViaWorker,
+ fetchPublicAlbumsUploadURLs,
+ fetchUploadURLs,
PhotosUploadHTTPClient,
PublicAlbumsUploadHTTPClient,
putFile,
@@ -208,14 +210,12 @@ class UploadService {
private async _refillUploadURLs() {
let urls: ObjectUploadURL[];
if (this.publicAlbumsCredentials) {
- urls = await publicAlbumsHTTPClient.fetchUploadURLs(
+ urls = await fetchPublicAlbumsUploadURLs(
this.pendingUploadCount,
this.publicAlbumsCredentials,
);
} else {
- urls = await photosHTTPClient.fetchUploadURLs(
- this.pendingUploadCount,
- );
+ urls = await fetchUploadURLs(this.pendingUploadCount);
}
urls.forEach((u) => this.uploadURLs.push(u));
}