fix getUniqueFileSaveName , by providing collectionPath too for checking if file already exists at the fileSavePath
This commit is contained in:
parent
1476e68e3c
commit
3dd90ba538
|
@ -351,7 +351,10 @@ class ExportService {
|
|||
|
||||
async downloadAndSave(file: File, collectionPath: string) {
|
||||
file.metadata = mergeMetadata([file])[0].metadata;
|
||||
const fileSaveName = getUniqueFileSaveName(file.metadata.title);
|
||||
const fileSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
file.metadata.title
|
||||
);
|
||||
let fileStream = await retryAsyncFunction(() =>
|
||||
downloadManager.downloadFile(file)
|
||||
);
|
||||
|
@ -384,12 +387,18 @@ class ExportService {
|
|||
const originalName = fileNameWithoutExtension(file.metadata.title);
|
||||
const motionPhoto = await decodeMotionPhoto(fileBlob, originalName);
|
||||
const imageStream = generateStreamFromArrayBuffer(motionPhoto.image);
|
||||
const imageSaveName = getUniqueFileSaveName(motionPhoto.imageNameTitle);
|
||||
const imageSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
motionPhoto.imageNameTitle
|
||||
);
|
||||
this.saveMediaFile(collectionPath, imageSaveName, imageStream);
|
||||
this.saveMetadataFile(collectionPath, imageSaveName, file.metadata);
|
||||
|
||||
const videoStream = generateStreamFromArrayBuffer(motionPhoto.video);
|
||||
const videoSaveName = getUniqueFileSaveName(motionPhoto.videoNameTitle);
|
||||
const videoSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
motionPhoto.videoNameTitle
|
||||
);
|
||||
this.saveMediaFile(collectionPath, videoSaveName, videoStream);
|
||||
this.saveMetadataFile(collectionPath, videoSaveName, file.metadata);
|
||||
}
|
||||
|
@ -500,7 +509,10 @@ class ExportService {
|
|||
file
|
||||
);
|
||||
file = mergeMetadata([file])[0];
|
||||
const newFileSaveName = getUniqueFileSaveName(file.metadata.title);
|
||||
const newFileSaveName = getUniqueFileSaveName(
|
||||
collectionIDPathMap.get(file.collectionID),
|
||||
file.metadata.title
|
||||
);
|
||||
|
||||
const newFileSavePath = getFileSavePath(
|
||||
collectionIDPathMap.get(file.collectionID),
|
||||
|
|
|
@ -118,16 +118,22 @@ export const getUniqueCollectionFolderPath = (
|
|||
export const getMetadataFolderPath = (collectionFolderPath: string) =>
|
||||
`${collectionFolderPath}/${METADATA_FOLDER_NAME}`;
|
||||
|
||||
export const getUniqueFileSaveName = (filename: string) => {
|
||||
export const getUniqueFileSaveName = (
|
||||
collectionPath: string,
|
||||
filename: string
|
||||
) => {
|
||||
let fileSaveName = sanitizeName(filename);
|
||||
const count = 1;
|
||||
while (exportService.exists(fileSaveName)) {
|
||||
const filenameParts = splitFilenameAndExtension(fileSaveName);
|
||||
let count = 1;
|
||||
while (
|
||||
exportService.exists(getFileSavePath(collectionPath, fileSaveName))
|
||||
) {
|
||||
const filenameParts = splitFilenameAndExtension(filename);
|
||||
if (filenameParts[1]) {
|
||||
fileSaveName = `${filenameParts[0]}(${count}).${filenameParts[1]}`;
|
||||
} else {
|
||||
fileSaveName = `${filenameParts[0]}(${count})`;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return fileSaveName;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue