Skip to content

armgit / ente

Public Imported from GitHub
0

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

And the next

Manav Rathia7f5061eb617
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index 3359f8c35f..216c4eface 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -31,7 +31,6 @@ import { SetFiles } from "types/gallery";
import {
FileWithCollection,
PublicUploadProps,
- type FileWithCollection2 as ClusteredFile,
type LivePhotoAssets2,
} from "types/upload";
import {
@@ -485,16 +484,16 @@ class UploadManager {
while (this.filesToBeUploaded.length > 0) {
this.abortIfCancelled();
- let fileWithCollection = this.filesToBeUploaded.pop();
- const { collectionID } = fileWithCollection;
+ const clusteredFile = this.filesToBeUploaded.pop();
+ const { localID, collectionID } = clusteredFile;
const collection = this.collections.get(collectionID);
- fileWithCollection = { ...fileWithCollection, collection };
+ const uploadableFile = { ...clusteredFile, collection };
- uiService.setFileProgress(fileWithCollection.localID, 0);
+ uiService.setFileProgress(localID, 0);
await wait(0);
- const { fileUploadResult, uploadedFile } = await uploader(
- fileWithCollection,
+ const { uploadResult, uploadedFile } = await uploader(
+ uploadableFile,
this.uploaderName,
this.existingFiles,
this.parsedMetadataJSONMap,
@@ -516,46 +515,43 @@ class UploadManager {
);
const finalUploadResult = await this.postUploadTask(
- fileUploadResult,
+ uploadableFile,
+ uploadResult,
uploadedFile,
- fileWithCollection,
);
- this.uiService.moveFileToResultList(
- fileWithCollection.localID,
- finalUploadResult,
- );
+ this.uiService.moveFileToResultList(localID, finalUploadResult);
this.uiService.increaseFileUploaded();
UploadService.reducePendingUploadCount();
}
}
private async postUploadTask(
- fileUploadResult: UPLOAD_RESULT,
- uploadedFile: EncryptedEnteFile | EnteFile | null,
- fileWithCollection: ClusteredFile,
+ uploadableFile: UploadableFile,
+ uploadResult: UPLOAD_RESULT,
+ uploadedFile: EncryptedEnteFile | EnteFile | undefined,
) {
+ log.info(`Upload completed with result: ${uploadResult}`);
try {
let decryptedFile: EnteFile;
- log.info(`Upload completed with result: ${fileUploadResult}`);
- await this.removeFromPendingUploads(fileWithCollection);
- switch (fileUploadResult) {
+ await this.removeFromPendingUploads(uploadableFile);
+ switch (uploadResult) {
case UPLOAD_RESULT.FAILED:
case UPLOAD_RESULT.BLOCKED:
- this.failedFiles.push(fileWithCollection);
+ this.failedFiles.push(uploadableFile);
break;
case UPLOAD_RESULT.ALREADY_UPLOADED:
decryptedFile = uploadedFile as EnteFile;
break;
case UPLOAD_RESULT.ADDED_SYMLINK:
decryptedFile = uploadedFile as EnteFile;
- fileUploadResult = UPLOAD_RESULT.UPLOADED;
+ uploadResult = UPLOAD_RESULT.UPLOADED;
break;
case UPLOAD_RESULT.UPLOADED:
case UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL:
decryptedFile = await decryptFile(
uploadedFile as EncryptedEnteFile,
- fileWithCollection.collection.key,
+ uploadableFile.collection.key,
);
break;
case UPLOAD_RESULT.UNSUPPORTED:
@@ -563,23 +559,21 @@ class UploadManager {
// no-op
break;
default:
- throw new Error(
- `Invalid Upload Result ${fileUploadResult}`,
- );
+ throw new Error(`Invalid Upload Result ${uploadResult}`);
}
if (
[
UPLOAD_RESULT.ADDED_SYMLINK,
UPLOAD_RESULT.UPLOADED,
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL,
- ].includes(fileUploadResult)
+ ].includes(uploadResult)
) {
try {
eventBus.emit(Events.FILE_UPLOADED, {
enteFile: decryptedFile,
localFile:
- fileWithCollection.file ??
- fileWithCollection.livePhotoAssets.image,
+ uploadableFile.fileOrPath ??
+ uploadableFile.livePhotoAssets.image,
});
} catch (e) {
log.warn("Ignoring error in fileUploaded handlers", e);
@@ -587,11 +581,11 @@ class UploadManager {
this.updateExistingFiles(decryptedFile);
}
await this.watchFolderCallback(
- fileUploadResult,
- fileWithCollection,
+ uploadResult,
+ uploadableFile,
uploadedFile as EncryptedEnteFile,
);
- return fileUploadResult;
+ return uploadResult;
} catch (e) {
log.error("failed to do post file upload action", e);
return UPLOAD_RESULT.FAILED;
@@ -729,6 +723,11 @@ const makeFileWithCollectionIDAndName = (
};
};
+/**
+ * A file with both parts of a live photo clubbed together.
+ *
+ * See: [Note: Intermediate file types during upload].
+ */
type ClusteredFile = {
localID: number;
collectionID: number;
@@ -738,6 +737,16 @@ type ClusteredFile = {
livePhotoAssets?: LivePhotoAssets2;
};
+/**
+ * The file that we hand off to the uploader. Essentially {@link ClusteredFile}
+ * with the {@link collection} attached to it.
+ *
+ * See: [Note: Intermediate file types during upload].
+ */
+export type UploadableFile = ClusteredFile & {
+ collection: Collection;
+};
+
const splitMetadataAndMediaFiles = (
files: FileWithCollectionIDAndName[],
): [
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index c8e56c77eb..7d259a1c8e 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -25,6 +25,7 @@ import { parseImageMetadata } from "services/exif";
import * as ffmpeg from "services/ffmpeg";
import {
EnteFile,
+ type EncryptedEnteFile,
type FilePublicMagicMetadata,
type FilePublicMagicMetadataProps,
} from "types/file";
@@ -40,7 +41,6 @@ import {
UploadAsset,
UploadFile,
UploadURL,
- type FileWithCollection2,
type LivePhotoAssets2,
type UploadAsset2,
} from "types/upload";
@@ -63,6 +63,7 @@ import {
generateThumbnailWeb,
} from "./thumbnail";
import UploadHttpClient from "./uploadHttpClient";
+import type { UploadableFile } from "./uploadManager";
/** Upload files to cloud storage */
class UploadService {
@@ -160,12 +161,12 @@ type MakeProgressTracker = (
) => unknown;
interface UploadResponse {
- fileUploadResult: UPLOAD_RESULT;
- uploadedFile?: EnteFile;
+ uploadResult: UPLOAD_RESULT;
+ uploadedFile?: EncryptedEnteFile | EnteFile;
}
export const uploader = async (
- fileWithCollection: FileWithCollection2,
+ fileWithCollection: UploadableFile,
uploaderName: string,
existingFiles: EnteFile[],
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,
@@ -200,7 +201,7 @@ export const uploader = async (
const maxFileSize = 4 * 1024 * 1024 * 1024; /* 4 GB */
if (fileSize >= maxFileSize)
- return { fileUploadResult: UPLOAD_RESULT.TOO_LARGE };
+ return { uploadResult: UPLOAD_RESULT.TOO_LARGE };
abortIfCancelled();
@@ -225,7 +226,7 @@ export const uploader = async (
);
if (matchInSameCollection) {
return {
- fileUploadResult: UPLOAD_RESULT.ALREADY_UPLOADED,
+ uploadResult: UPLOAD_RESULT.ALREADY_UPLOADED,
uploadedFile: matchInSameCollection,
};
} else {
@@ -234,7 +235,7 @@ export const uploader = async (
symlink.collectionID = collection.id;
await addToCollection(collection, [symlink]);
return {
- fileUploadResult: UPLOAD_RESULT.ADDED_SYMLINK,
+ uploadResult: UPLOAD_RESULT.ADDED_SYMLINK,
uploadedFile: symlink,
};
}
@@ -287,7 +288,7 @@ export const uploader = async (
});
return {
- fileUploadResult: metadata.hasStaticThumbnail
+ uploadResult: metadata.hasStaticThumbnail
? UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL
: UPLOAD_RESULT.UPLOADED,
uploadedFile: uploadedFile,
@@ -304,16 +305,15 @@ export const uploader = async (
const error = handleUploadError(e);
switch (error.message) {
case CustomError.ETAG_MISSING:
- return { fileUploadResult: UPLOAD_RESULT.BLOCKED };
+ return { uploadResult: UPLOAD_RESULT.BLOCKED };
case CustomError.UNSUPPORTED_FILE_FORMAT:
- return { fileUploadResult: UPLOAD_RESULT.UNSUPPORTED };
+ return { uploadResult: UPLOAD_RESULT.UNSUPPORTED };
case CustomError.FILE_TOO_LARGE:
return {
- fileUploadResult:
- UPLOAD_RESULT.LARGER_THAN_AVAILABLE_STORAGE,
+ uploadResult: UPLOAD_RESULT.LARGER_THAN_AVAILABLE_STORAGE,
};
default:
- return { fileUploadResult: UPLOAD_RESULT.FAILED };
+ return { uploadResult: UPLOAD_RESULT.FAILED };
}
}
};