Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reroute

Manav Rathi2baa16bba77e
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index 1229248530..90e506f68d 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -502,6 +502,7 @@ class UploadManager {
const uiService = this.uiService;
const uploadContext = {
isCFUploadProxyDisabled: shouldDisableCFUploadProxy(),
+ publicAlbumsCredentials: this.publicAlbumsCredentials,
abortIfCancelled: this.abortIfCancelled.bind(this),
updateUploadProgress:
uiService.updateUploadProgress.bind(uiService),
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index bce9a84c94..3d629bdadc 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -157,12 +157,6 @@ class UploadService {
return url;
}
- async postFile(file: PostEnteFileRequest) {
- return this.publicAlbumsCredentials
- ? postPublicAlbumsEnteFile(file, this.publicAlbumsCredentials)
- : postEnteFile(file);
- }
-
private async refillUploadURLs() {
try {
if (!this.activeUploadURLRefill) {
@@ -609,6 +603,14 @@ interface UploadContext {
* See {@link shouldDisableCFUploadProxy} for more details.
*/
isCFUploadProxyDisabled: boolean;
+ /**
+ * If present, then the upload is happening in the context of the public
+ * albums app and these are the credentials that should be used for
+ * performing API requests (instead of trying to obtain and use the
+ * credentials for the logged in user, as happens when we're running in the
+ * context of the photos app).
+ */
+ publicAlbumsCredentials: PublicAlbumsCredentials | undefined;
/**
* A function that the upload sequence should use to periodically check in
* and see if the upload has been cancelled by the user.
@@ -764,12 +766,17 @@ export const upload = async (
abortIfCancelled();
- const uploadedFile = await uploadService.postFile({
+ const newFileRequest = {
collectionID: collection.id,
encryptedKey: encryptedFileKey.encryptedData,
keyDecryptionNonce: encryptedFileKey.nonce,
...backupedFile,
- });
+ };
+
+ const uploadedFile = await createRemoteFile(
+ newFileRequest,
+ uploadContext,
+ );
return {
uploadResult: metadata.hasStaticThumbnail
@@ -1766,3 +1773,24 @@ const nextMultipartUploadPart = async (
}
return mergeUint8Arrays(chunks);
};
+
+/**
+ * Finalize an upload by creating an {@link EnteFile} on remote.
+ */
+const createRemoteFile = async (
+ newFileRequest: PostEnteFileRequest,
+ uploadContext: UploadContext,
+) => {
+ const { publicAlbumsCredentials, abortIfCancelled } = uploadContext;
+
+ abortIfCancelled();
+
+ if (publicAlbumsCredentials) {
+ return postPublicAlbumsEnteFile(
+ newFileRequest,
+ publicAlbumsCredentials,
+ );
+ } else {
+ return postEnteFile(newFileRequest);
+ }
+};