Merge branch 'new-upload-result-symlink-added' into watch
This commit is contained in:
commit
38ce43af83
|
@ -45,6 +45,7 @@ export enum UPLOAD_RESULT {
|
||||||
LARGER_THAN_AVAILABLE_STORAGE,
|
LARGER_THAN_AVAILABLE_STORAGE,
|
||||||
UPLOADED,
|
UPLOADED,
|
||||||
UPLOADED_WITH_STATIC_THUMBNAIL,
|
UPLOADED_WITH_STATIC_THUMBNAIL,
|
||||||
|
ADDED_SYMLINK,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MAX_FILE_SIZE_SUPPORTED = 4 * 1024 * 1024 * 1024; // 4 GB
|
export const MAX_FILE_SIZE_SUPPORTED = 4 * 1024 * 1024 * 1024; // 4 GB
|
||||||
|
|
|
@ -332,8 +332,7 @@ class UploadManager {
|
||||||
this.existingFilesCollectionWise.get(collectionID) ?? [];
|
this.existingFilesCollectionWise.get(collectionID) ?? [];
|
||||||
const collection = this.collections.get(collectionID);
|
const collection = this.collections.get(collectionID);
|
||||||
fileWithCollection = { ...fileWithCollection, collection };
|
fileWithCollection = { ...fileWithCollection, collection };
|
||||||
const { fileUploadResult, uploadedFile, skipDecryption } =
|
const { fileUploadResult, uploadedFile } = await uploader(
|
||||||
await uploader(
|
|
||||||
worker,
|
worker,
|
||||||
existingFilesInCollection,
|
existingFilesInCollection,
|
||||||
this.existingFiles,
|
this.existingFiles,
|
||||||
|
@ -357,7 +356,6 @@ class UploadManager {
|
||||||
await this.postUploadTask(
|
await this.postUploadTask(
|
||||||
fileUploadResult,
|
fileUploadResult,
|
||||||
uploadedFile,
|
uploadedFile,
|
||||||
skipDecryption,
|
|
||||||
fileWithCollection
|
fileWithCollection
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -366,65 +364,45 @@ class UploadManager {
|
||||||
async postUploadTask(
|
async postUploadTask(
|
||||||
fileUploadResult: UPLOAD_RESULT,
|
fileUploadResult: UPLOAD_RESULT,
|
||||||
uploadedFile: EnteFile,
|
uploadedFile: EnteFile,
|
||||||
skipDecryption: boolean,
|
|
||||||
fileWithCollection: FileWithCollection
|
fileWithCollection: FileWithCollection
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
let decryptedFile: EnteFile;
|
||||||
logUploadInfo(`uploadedFile ${JSON.stringify(uploadedFile)}`);
|
logUploadInfo(`uploadedFile ${JSON.stringify(uploadedFile)}`);
|
||||||
|
this.updateElectronRemainingFiles(fileWithCollection);
|
||||||
if (
|
switch (fileUploadResult) {
|
||||||
(fileUploadResult === UPLOAD_RESULT.UPLOADED ||
|
case UPLOAD_RESULT.FAILED:
|
||||||
fileUploadResult ===
|
case UPLOAD_RESULT.BLOCKED:
|
||||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL) &&
|
|
||||||
!skipDecryption
|
|
||||||
) {
|
|
||||||
const decryptedFile = await decryptFile(
|
|
||||||
uploadedFile,
|
|
||||||
fileWithCollection.collection.key
|
|
||||||
);
|
|
||||||
this.existingFiles.push(decryptedFile);
|
|
||||||
this.existingFiles = sortFiles(this.existingFiles);
|
|
||||||
await setLocalFiles(this.existingFiles);
|
|
||||||
this.setFiles(preservePhotoswipeProps(this.existingFiles));
|
|
||||||
if (
|
|
||||||
!this.existingFilesCollectionWise.has(
|
|
||||||
decryptedFile.collectionID
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.existingFilesCollectionWise.set(
|
|
||||||
decryptedFile.collectionID,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.existingFilesCollectionWise
|
|
||||||
.get(decryptedFile.collectionID)
|
|
||||||
.push(decryptedFile);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
fileUploadResult === UPLOAD_RESULT.FAILED ||
|
|
||||||
fileUploadResult === UPLOAD_RESULT.BLOCKED
|
|
||||||
) {
|
|
||||||
this.failedFiles.push(fileWithCollection);
|
this.failedFiles.push(fileWithCollection);
|
||||||
}
|
break;
|
||||||
|
case UPLOAD_RESULT.ALREADY_UPLOADED:
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
this.remainingFiles = this.remainingFiles.filter(
|
|
||||||
(file) =>
|
|
||||||
!areFileWithCollectionsSame(file, fileWithCollection)
|
|
||||||
);
|
|
||||||
ImportService.updatePendingUploads(this.remainingFiles);
|
|
||||||
|
|
||||||
if (
|
|
||||||
fileUploadResult === UPLOAD_RESULT.UPLOADED ||
|
|
||||||
fileUploadResult ===
|
|
||||||
UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL ||
|
|
||||||
fileUploadResult === UPLOAD_RESULT.ALREADY_UPLOADED
|
|
||||||
) {
|
|
||||||
await watchFolderService.onFileUpload(
|
await watchFolderService.onFileUpload(
|
||||||
fileWithCollection,
|
fileWithCollection,
|
||||||
uploadedFile
|
uploadedFile
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case UPLOAD_RESULT.ADDED_SYMLINK:
|
||||||
|
decryptedFile = uploadedFile;
|
||||||
|
break;
|
||||||
|
case UPLOAD_RESULT.UPLOADED:
|
||||||
|
case UPLOAD_RESULT.UPLOADED_WITH_STATIC_THUMBNAIL:
|
||||||
|
decryptedFile = await decryptFile(
|
||||||
|
uploadedFile,
|
||||||
|
fileWithCollection.collection.key
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
if (decryptedFile) {
|
||||||
|
await this.updateExistingFiles(decryptedFile);
|
||||||
|
this.updateExistingCollections(decryptedFile);
|
||||||
|
await this.watchFolderCallback(
|
||||||
|
fileWithCollection,
|
||||||
|
uploadedFile
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'failed to do post file upload action');
|
logError(e, 'failed to do post file upload action');
|
||||||
|
@ -436,6 +414,48 @@ class UploadManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async watchFolderCallback(
|
||||||
|
fileWithCollection: FileWithCollection,
|
||||||
|
uploadedFile: EnteFile
|
||||||
|
) {
|
||||||
|
if (isElectron()) {
|
||||||
|
await watchFolderService.onFileUpload(
|
||||||
|
fileWithCollection,
|
||||||
|
uploadedFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateExistingCollections(decryptedFile: EnteFile) {
|
||||||
|
if (!this.existingFilesCollectionWise.has(decryptedFile.collectionID)) {
|
||||||
|
this.existingFilesCollectionWise.set(
|
||||||
|
decryptedFile.collectionID,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.existingFilesCollectionWise
|
||||||
|
.get(decryptedFile.collectionID)
|
||||||
|
.push(decryptedFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateExistingFiles(decryptedFile: EnteFile) {
|
||||||
|
this.existingFiles.push(decryptedFile);
|
||||||
|
this.existingFiles = sortFiles(this.existingFiles);
|
||||||
|
await setLocalFiles(this.existingFiles);
|
||||||
|
this.setFiles(preservePhotoswipeProps(this.existingFiles));
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateElectronRemainingFiles(
|
||||||
|
fileWithCollection: FileWithCollection
|
||||||
|
) {
|
||||||
|
if (isElectron()) {
|
||||||
|
this.remainingFiles = this.remainingFiles.filter(
|
||||||
|
(file) => !areFileWithCollectionsSame(file, fileWithCollection)
|
||||||
|
);
|
||||||
|
ImportService.updatePendingUploads(this.remainingFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async retryFailedFiles() {
|
async retryFailedFiles() {
|
||||||
await this.queueFilesForUpload(this.failedFiles, [
|
await this.queueFilesForUpload(this.failedFiles, [
|
||||||
...this.collections.values(),
|
...this.collections.values(),
|
||||||
|
|
|
@ -20,7 +20,6 @@ import { addToCollection } from 'services/collectionService';
|
||||||
interface UploadResponse {
|
interface UploadResponse {
|
||||||
fileUploadResult: UPLOAD_RESULT;
|
fileUploadResult: UPLOAD_RESULT;
|
||||||
uploadedFile?: EnteFile;
|
uploadedFile?: EnteFile;
|
||||||
skipDecryption?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function uploader(
|
export default async function uploader(
|
||||||
|
@ -76,9 +75,8 @@ export default async function uploader(
|
||||||
resultFile.collectionID = collection.id;
|
resultFile.collectionID = collection.id;
|
||||||
await addToCollection(collection, [resultFile]);
|
await addToCollection(collection, [resultFile]);
|
||||||
return {
|
return {
|
||||||
fileUploadResult: UPLOAD_RESULT.UPLOADED,
|
fileUploadResult: UPLOAD_RESULT.ADDED_SYMLINK,
|
||||||
uploadedFile: resultFile,
|
uploadedFile: resultFile,
|
||||||
skipDecryption: true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue