Shorten chunk

This commit is contained in:
Manav Rathi 2024-04-23 20:50:15 +05:30
parent 86a102c47d
commit e1a3475faa
No known key found for this signature in database

View file

@ -212,38 +212,26 @@ export const uploader = async (
fileTypeInfo, fileTypeInfo,
); );
const matchingExistingFiles = findMatchingExistingFiles( const matches = findMatchingExistingFiles(existingFiles, metadata);
existingFiles, const anyMatch = matches?.length > 0 ? matches[0] : undefined;
metadata,
);
if (matchingExistingFiles?.length) { if (anyMatch) {
const matchingExistingFilesCollectionIDs = const matchInSameCollection = matches.find(
matchingExistingFiles.map((e) => e.collectionID); (f) => f.collectionID == collection.id,
);
if (matchingExistingFilesCollectionIDs.includes(collection.id)) { if (matchInSameCollection) {
log.info(
`Skipping upload of ${name} since it is already present in the collection`,
);
const sameCollectionMatchingExistingFile =
matchingExistingFiles.find(
(f) => f.collectionID === collection.id,
);
return { return {
fileUploadResult: UPLOAD_RESULT.ALREADY_UPLOADED, fileUploadResult: UPLOAD_RESULT.ALREADY_UPLOADED,
uploadedFile: sameCollectionMatchingExistingFile, uploadedFile: matchInSameCollection,
}; };
} else { } else {
log.info( // Any of the matching files can be used to add a symlink.
`Symlinking ${name} to existing file in ${matchingExistingFilesCollectionIDs.length} collections`, const symlink = Object.assign({}, anyMatch);
); symlink.collectionID = collection.id;
// any of the matching file can used to add a symlink await addToCollection(collection, [symlink]);
const resultFile = Object.assign({}, matchingExistingFiles[0]);
resultFile.collectionID = collection.id;
await addToCollection(collection, [resultFile]);
return { return {
fileUploadResult: UPLOAD_RESULT.ADDED_SYMLINK, fileUploadResult: UPLOAD_RESULT.ADDED_SYMLINK,
uploadedFile: resultFile, uploadedFile: symlink,
}; };
} }
} }