This commit is contained in:
Manav Rathi 2024-04-29 21:12:47 +05:30
parent fca398f296
commit eb608f4bdd
No known key found for this signature in database
2 changed files with 30 additions and 29 deletions

View file

@ -350,9 +350,9 @@ class UploadManager {
ComlinkWorker<typeof DedicatedCryptoWorker> ComlinkWorker<typeof DedicatedCryptoWorker>
>(maxConcurrentUploads); >(maxConcurrentUploads);
private parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>; private parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>;
private filesToBeUploaded: ClusteredFile[]; private filesToBeUploaded: ClusteredUploadItem[];
private remainingFiles: ClusteredFile[] = []; private remainingFiles: ClusteredUploadItem[] = [];
private failedFiles: ClusteredFile[]; private failedFiles: ClusteredUploadItem[];
private existingFiles: EnteFile[]; private existingFiles: EnteFile[];
private setFiles: SetFiles; private setFiles: SetFiles;
private collections: Map<number, Collection>; private collections: Map<number, Collection>;
@ -533,7 +533,7 @@ class UploadManager {
} }
} }
private async uploadMediaFiles(mediaFiles: ClusteredFile[]) { private async uploadMediaFiles(mediaFiles: ClusteredUploadItem[]) {
this.filesToBeUploaded = [...this.filesToBeUploaded, ...mediaFiles]; this.filesToBeUploaded = [...this.filesToBeUploaded, ...mediaFiles];
if (isElectron()) { if (isElectron()) {
@ -608,7 +608,7 @@ class UploadManager {
} }
private async postUploadTask( private async postUploadTask(
uploadableFile: UploadableFile, uploadableFile: UploadableUploadItem,
uploadResult: UPLOAD_RESULT, uploadResult: UPLOAD_RESULT,
uploadedFile: EncryptedEnteFile | EnteFile | undefined, uploadedFile: EncryptedEnteFile | EnteFile | undefined,
) { ) {
@ -655,7 +655,7 @@ class UploadManager {
eventBus.emit(Events.FILE_UPLOADED, { eventBus.emit(Events.FILE_UPLOADED, {
enteFile: decryptedFile, enteFile: decryptedFile,
localFile: localFile:
uploadableFile.fileOrPath ?? uploadableFile.uploadItem ??
uploadableFile.livePhotoAssets.image, uploadableFile.livePhotoAssets.image,
}); });
} catch (e) { } catch (e) {
@ -677,7 +677,7 @@ class UploadManager {
private async watchFolderCallback( private async watchFolderCallback(
fileUploadResult: UPLOAD_RESULT, fileUploadResult: UPLOAD_RESULT,
fileWithCollection: ClusteredFile, fileWithCollection: ClusteredUploadItem,
uploadedFile: EncryptedEnteFile, uploadedFile: EncryptedEnteFile,
) { ) {
if (isElectron()) { if (isElectron()) {
@ -720,7 +720,7 @@ class UploadManager {
this.setFiles((files) => sortFiles([...files, decryptedFile])); this.setFiles((files) => sortFiles([...files, decryptedFile]));
} }
private async removeFromPendingUploads({ localID }: ClusteredFile) { private async removeFromPendingUploads({ localID }: ClusteredUploadItem) {
const electron = globalThis.electron; const electron = globalThis.electron;
if (electron) { if (electron) {
this.remainingFiles = this.remainingFiles.filter( this.remainingFiles = this.remainingFiles.filter(
@ -747,20 +747,21 @@ export default new UploadManager();
* *
* - The input is {@link UploadItemWithCollection}. This can either be a new * - The input is {@link UploadItemWithCollection}. This can either be a new
* {@link UploadItemWithCollection}, in which case it'll only have a * {@link UploadItemWithCollection}, in which case it'll only have a
* {@link localID}, {@link collectionID} and a {@link fileOrPath}. Or it could * {@link localID}, {@link collectionID} and a {@link uploadItem}. Or it could
* be a retry, in which case it'll not have a {@link fileOrPath} but instead * be a retry, in which case it'll not have a {@link uploadItem} but instead
* will have data from a previous stage (concretely, it'll just be a * will have data from a previous stage (concretely, it'll just be a
* relabelled {@link ClusteredFile}), like a snake eating its tail. * relabelled {@link ClusteredUploadItem}), like a snake eating its tail.
* *
* - Immediately we convert it to {@link UploadItemWithCollectionIDAndName}. This is * - Immediately we convert it to {@link UploadItemWithCollectionIDAndName}.
* to mostly systematize what we have, and also attach a {@link fileName}. * This is to mostly systematize what we have, and also attach a
* {@link fileName}.
* *
* - These then get converted to "assets", whereby both parts of a live photo * - These then get converted to "assets", whereby both parts of a live photo
* are combined. This is a {@link ClusteredFile}. * are combined. This is a {@link ClusteredUploadItem}.
* *
* - On to the {@link ClusteredFile} we attach the corresponding * - On to the {@link ClusteredUploadItem} we attach the corresponding
* {@link collection}, giving us {@link UploadableFile}. This is what gets * {@link collection}, giving us {@link UploadableUploadItem}. This is what
* queued and then passed to the {@link uploader}. * gets queued and then passed to the {@link uploader}.
*/ */
type UploadItemWithCollectionIDAndName = { type UploadItemWithCollectionIDAndName = {
/** A unique ID for the duration of the upload */ /** A unique ID for the duration of the upload */
@ -804,26 +805,26 @@ const makeUploadItemWithCollectionIDAndName = (
}; };
/** /**
* A file with both parts of a live photo clubbed together. * An upload item with both parts of a live photo clubbed together.
* *
* See: [Note: Intermediate file types during upload]. * See: [Note: Intermediate file types during upload].
*/ */
type ClusteredFile = { type ClusteredUploadItem = {
localID: number; localID: number;
collectionID: number; collectionID: number;
fileName: string; fileName: string;
isLivePhoto: boolean; isLivePhoto: boolean;
fileOrPath?: File | string; uploadItem?: UploadItem;
livePhotoAssets?: LivePhotoAssets; livePhotoAssets?: LivePhotoAssets;
}; };
/** /**
* The file that we hand off to the uploader. Essentially {@link ClusteredFile} * The file that we hand off to the uploader. Essentially
* with the {@link collection} attached to it. * {@link ClusteredUploadItem} with the {@link collection} attached to it.
* *
* See: [Note: Intermediate file types during upload]. * See: [Note: Intermediate file types during upload].
*/ */
export type UploadableFile = ClusteredFile & { export type UploadableUploadItem = ClusteredUploadItem & {
collection: Collection; collection: Collection;
}; };
@ -844,13 +845,13 @@ const splitMetadataAndMediaFiles = (
const updatePendingUploads = async ( const updatePendingUploads = async (
electron: Electron, electron: Electron,
files: ClusteredFile[], files: ClusteredUploadItem[],
) => { ) => {
const paths = files const paths = files
.map((file) => .map((file) =>
file.isLivePhoto file.isLivePhoto
? [file.livePhotoAssets.image, file.livePhotoAssets.video] ? [file.livePhotoAssets.image, file.livePhotoAssets.video]
: [file.fileOrPath], : [file.uploadItem],
) )
.flat() .flat()
.map((f) => getFilePathElectron(f)); .map((f) => getFilePathElectron(f));
@ -878,7 +879,7 @@ const cancelRemainingUploads = async () => {
const clusterLivePhotos = async ( const clusterLivePhotos = async (
files: UploadItemWithCollectionIDAndName[], files: UploadItemWithCollectionIDAndName[],
) => { ) => {
const result: ClusteredFile[] = []; const result: ClusteredUploadItem[] = [];
files files
.sort((f, g) => .sort((f, g) =>
nameAndExtension(f.fileName)[0].localeCompare( nameAndExtension(f.fileName)[0].localeCompare(

View file

@ -51,7 +51,7 @@ import {
generateThumbnailWeb, generateThumbnailWeb,
} from "./thumbnail"; } from "./thumbnail";
import UploadHttpClient from "./uploadHttpClient"; import UploadHttpClient from "./uploadHttpClient";
import type { UploadItem, UploadableFile } from "./uploadManager"; import type { UploadItem, UploadableUploadItem } from "./uploadManager";
/** /**
* A readable stream for a file, and its associated size and last modified time. * A readable stream for a file, and its associated size and last modified time.
@ -315,14 +315,14 @@ interface UploadResponse {
} }
/** /**
* Upload the given {@link UploadableFile} * Upload the given {@link UploadableUploadItem}
* *
* This is lower layer implementation of the upload. It is invoked by * This is lower layer implementation of the upload. It is invoked by
* {@link UploadManager} after it has assembled all the relevant bits we need to * {@link UploadManager} after it has assembled all the relevant bits we need to
* go forth and upload. * go forth and upload.
*/ */
export const uploader = async ( export const uploader = async (
{ collection, localID, fileName, ...uploadAsset }: UploadableFile, { collection, localID, fileName, ...uploadAsset }: UploadableUploadItem,
uploaderName: string, uploaderName: string,
existingFiles: EnteFile[], existingFiles: EnteFile[],
parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>, parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,