π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Conv
Manav Rathi0d77c0a49b80
diff --git a/web/packages/gallery/services/upload/remote.ts b/web/packages/gallery/services/upload/remote.tsindex d093dbcbc8..56e33e5732 100644--- a/web/packages/gallery/services/upload/remote.ts+++ b/web/packages/gallery/services/upload/remote.ts@@ -412,59 +412,65 @@ export const completeMultipartUploadViaWorker = async ();/**- * Lowest layer for file upload related HTTP operations when we're running in- * the context of the photos app.+ * Create a new {@link EnteFile} on remote by providing remote with information+ * about the file's contents (objects) that were uploaded, and other metadata+ * about the file.+ *+ * Remote only, does not modify local state.+ *+ * Since this function is the last step after a potentially long upload to S3+ * remote of the file contents themselves, it has internal retries of the HTTP+ * request to avoid having transient issues spoil the party.+ *+ * @returns the newly created {@link EnteFile}.*/-export class PhotosUploadHTTPClient {- async uploadFile(uploadFile: UploadFile): Promise<EnteFile> {- try {- const url = await apiURL("/files");- const headers = await authenticatedRequestHeaders();- const response = await retryAsyncOperation(- () =>- HTTPService.post(- url,- uploadFile,- // @ts-ignore- null,- headers,- ),- { abortIfNeeded: handleUploadError },- );- return response.data;- } catch (e) {- log.error("upload Files Failed", e);- throw e;- }+export const postEnteFile = async (+ uploadFile: UploadFile,+): Promise<EnteFile> => {+ try {+ const url = await apiURL("/files");+ const headers = await authenticatedRequestHeaders();+ const response = await retryAsyncOperation(+ () =>+ HTTPService.post(+ url,+ uploadFile,+ // @ts-ignore+ null,+ headers,+ ),+ { abortIfNeeded: handleUploadError },+ );+ return response.data;+ } catch (e) {+ log.error("upload Files Failed", e);+ throw e;}-}+};/**- * Lowest layer for file upload related HTTP operations when we're running in- * the context of the public albums app.+ * Sibling of {@link postEnteFile} for public albums.*/-export class PublicAlbumsUploadHTTPClient {- async uploadFile(- uploadFile: UploadFile,- credentials: PublicAlbumsCredentials,- ): Promise<EnteFile> {- try {- const url = await apiURL("/public-collection/file");- const response = await retryAsyncOperation(- () =>- HTTPService.post(- url,- uploadFile,- // @ts-ignore- null,- authenticatedPublicAlbumsRequestHeaders(credentials),- ),- { abortIfNeeded: handleUploadError },- );- return response.data;- } catch (e) {- log.error("upload public File Failed", e);- throw e;- }+export const postPublicAlbumsEnteFile = async (+ uploadFile: UploadFile,+ credentials: PublicAlbumsCredentials,+): Promise<EnteFile> => {+ try {+ const url = await apiURL("/public-collection/file");+ const response = await retryAsyncOperation(+ () =>+ HTTPService.post(+ url,+ uploadFile,+ // @ts-ignore+ null,+ authenticatedPublicAlbumsRequestHeaders(credentials),+ ),+ { abortIfNeeded: handleUploadError },+ );+ return response.data;+ } catch (e) {+ log.error("upload public File Failed", e);+ throw e;}-}+};diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.tsindex 1e4a507329..e91ed9c139 100644--- a/web/packages/gallery/services/upload/upload-service.ts+++ b/web/packages/gallery/services/upload/upload-service.ts@@ -63,8 +63,8 @@ import {fetchPublicAlbumsMultipartUploadURLs,fetchPublicAlbumsUploadURLs,fetchUploadURLs,- PhotosUploadHTTPClient,- PublicAlbumsUploadHTTPClient,+ postEnteFile,+ postPublicAlbumsEnteFile,putFile,putFilePart,putFilePartViaWorker,@@ -78,9 +78,6 @@ import {generateThumbnailWeb,} from "./thumbnail";-const photosHTTPClient = new PhotosUploadHTTPClient();-const publicAlbumsHTTPClient = new PublicAlbumsUploadHTTPClient();-/*** A readable stream for a file, and its associated size and last modified time.*@@ -178,11 +175,8 @@ class UploadService {async uploadFile(uploadFile: UploadFile) {return this.publicAlbumsCredentials- ? publicAlbumsHTTPClient.uploadFile(- uploadFile,- this.publicAlbumsCredentials,- )- : photosHTTPClient.uploadFile(uploadFile);+ ? postPublicAlbumsEnteFile(uploadFile, this.publicAlbumsCredentials)+ : postEnteFile(uploadFile);}private async refillUploadURLs() {