add olderClient check and use olderClient logic
This commit is contained in:
parent
9dfd2e4ba7
commit
d814359e10
|
@ -105,9 +105,11 @@ class ExportService {
|
||||||
private exportRecordUpdater = new QueueProcessor<void>(1);
|
private exportRecordUpdater = new QueueProcessor<void>(1);
|
||||||
private stopExport: boolean = false;
|
private stopExport: boolean = false;
|
||||||
private pauseExport: boolean = false;
|
private pauseExport: boolean = false;
|
||||||
|
private oldClient: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
||||||
|
this.oldClient = !this.ElectronAPIs.exists;
|
||||||
}
|
}
|
||||||
async selectExportDirectory() {
|
async selectExportDirectory() {
|
||||||
return await this.ElectronAPIs.selectRootDirectory();
|
return await this.ElectronAPIs.selectRootDirectory();
|
||||||
|
@ -154,7 +156,13 @@ class ExportService {
|
||||||
(collectionA, collectionB) =>
|
(collectionA, collectionB) =>
|
||||||
collectionA.id - collectionB.id
|
collectionA.id - collectionB.id
|
||||||
);
|
);
|
||||||
await this.migrateExport(exportDir, collections, userPersonalFiles);
|
if (!this.isOldClient()) {
|
||||||
|
await this.migrateExport(
|
||||||
|
exportDir,
|
||||||
|
collections,
|
||||||
|
userPersonalFiles
|
||||||
|
);
|
||||||
|
}
|
||||||
const exportRecord = await this.getExportRecord(exportDir);
|
const exportRecord = await this.getExportRecord(exportDir);
|
||||||
|
|
||||||
if (exportType === ExportType.NEW) {
|
if (exportType === ExportType.NEW) {
|
||||||
|
@ -407,7 +415,7 @@ class ExportService {
|
||||||
for (const collection of newCollections) {
|
for (const collection of newCollections) {
|
||||||
const collectionFolderPath = getUniqueCollectionFolderPath(
|
const collectionFolderPath = getUniqueCollectionFolderPath(
|
||||||
exportFolder,
|
exportFolder,
|
||||||
collection.name
|
collection
|
||||||
);
|
);
|
||||||
await this.ElectronAPIs.checkExistsAndCreateCollectionDir(
|
await this.ElectronAPIs.checkExistsAndCreateCollectionDir(
|
||||||
collectionFolderPath
|
collectionFolderPath
|
||||||
|
@ -435,7 +443,7 @@ class ExportService {
|
||||||
|
|
||||||
const newCollectionFolderPath = getUniqueCollectionFolderPath(
|
const newCollectionFolderPath = getUniqueCollectionFolderPath(
|
||||||
exportFolder,
|
exportFolder,
|
||||||
collection.name
|
collection
|
||||||
);
|
);
|
||||||
await this.ElectronAPIs.checkExistsAndRename(
|
await this.ElectronAPIs.checkExistsAndRename(
|
||||||
oldCollectionFolderPath,
|
oldCollectionFolderPath,
|
||||||
|
@ -455,7 +463,8 @@ class ExportService {
|
||||||
file.metadata = mergeMetadata([file])[0].metadata;
|
file.metadata = mergeMetadata([file])[0].metadata;
|
||||||
const fileSaveName = getUniqueFileSaveName(
|
const fileSaveName = getUniqueFileSaveName(
|
||||||
collectionPath,
|
collectionPath,
|
||||||
file.metadata.title
|
file.metadata.title,
|
||||||
|
file.id
|
||||||
);
|
);
|
||||||
let fileStream = await retryAsyncFunction(() =>
|
let fileStream = await retryAsyncFunction(() =>
|
||||||
downloadManager.downloadFile(file)
|
downloadManager.downloadFile(file)
|
||||||
|
@ -495,7 +504,8 @@ class ExportService {
|
||||||
const imageStream = generateStreamFromArrayBuffer(motionPhoto.image);
|
const imageStream = generateStreamFromArrayBuffer(motionPhoto.image);
|
||||||
const imageSaveName = getUniqueFileSaveName(
|
const imageSaveName = getUniqueFileSaveName(
|
||||||
collectionPath,
|
collectionPath,
|
||||||
motionPhoto.imageNameTitle
|
motionPhoto.imageNameTitle,
|
||||||
|
file.id
|
||||||
);
|
);
|
||||||
this.saveMediaFile(collectionPath, imageSaveName, imageStream);
|
this.saveMediaFile(collectionPath, imageSaveName, imageStream);
|
||||||
await this.saveMetadataFile(
|
await this.saveMetadataFile(
|
||||||
|
@ -507,7 +517,8 @@ class ExportService {
|
||||||
const videoStream = generateStreamFromArrayBuffer(motionPhoto.video);
|
const videoStream = generateStreamFromArrayBuffer(motionPhoto.video);
|
||||||
const videoSaveName = getUniqueFileSaveName(
|
const videoSaveName = getUniqueFileSaveName(
|
||||||
collectionPath,
|
collectionPath,
|
||||||
motionPhoto.videoNameTitle
|
motionPhoto.videoNameTitle,
|
||||||
|
file.id
|
||||||
);
|
);
|
||||||
this.saveMediaFile(collectionPath, videoSaveName, videoStream);
|
this.saveMediaFile(collectionPath, videoSaveName, videoStream);
|
||||||
await this.saveMetadataFile(
|
await this.saveMetadataFile(
|
||||||
|
@ -545,6 +556,7 @@ class ExportService {
|
||||||
exists = (path: string) => {
|
exists = (path: string) => {
|
||||||
return this.ElectronAPIs.exists(path);
|
return this.ElectronAPIs.exists(path);
|
||||||
};
|
};
|
||||||
|
isOldClient = () => this.oldClient;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this function migrates the exportRecord file to apply any schema changes.
|
this function migrates the exportRecord file to apply any schema changes.
|
||||||
|
@ -595,7 +607,7 @@ class ExportService {
|
||||||
);
|
);
|
||||||
const newCollectionFolderPath = getUniqueCollectionFolderPath(
|
const newCollectionFolderPath = getUniqueCollectionFolderPath(
|
||||||
exportDir,
|
exportDir,
|
||||||
collection.name
|
collection
|
||||||
);
|
);
|
||||||
collectionIDPathMap.set(collection.id, newCollectionFolderPath);
|
collectionIDPathMap.set(collection.id, newCollectionFolderPath);
|
||||||
if (this.ElectronAPIs.exists(oldCollectionFolderPath)) {
|
if (this.ElectronAPIs.exists(oldCollectionFolderPath)) {
|
||||||
|
@ -632,7 +644,8 @@ class ExportService {
|
||||||
file = mergeMetadata([file])[0];
|
file = mergeMetadata([file])[0];
|
||||||
const newFileSaveName = getUniqueFileSaveName(
|
const newFileSaveName = getUniqueFileSaveName(
|
||||||
collectionIDPathMap.get(file.collectionID),
|
collectionIDPathMap.get(file.collectionID),
|
||||||
file.metadata.title
|
file.metadata.title,
|
||||||
|
file.id
|
||||||
);
|
);
|
||||||
|
|
||||||
const newFileSavePath = getFileSavePath(
|
const newFileSavePath = getFileSavePath(
|
||||||
|
|
|
@ -162,13 +162,16 @@ export const sanitizeName = (name: string) =>
|
||||||
|
|
||||||
export const getUniqueCollectionFolderPath = (
|
export const getUniqueCollectionFolderPath = (
|
||||||
dir: string,
|
dir: string,
|
||||||
collectionName: string
|
collection: Collection
|
||||||
): string => {
|
): string => {
|
||||||
let collectionFolderPath = `${dir}/${sanitizeName(collectionName)}`;
|
if (exportService.isOldClient()) {
|
||||||
|
return getOldCollectionFolderPath(dir, collection);
|
||||||
|
}
|
||||||
|
let collectionFolderPath = `${dir}/${sanitizeName(collection.name)}`;
|
||||||
let count = 1;
|
let count = 1;
|
||||||
while (exportService.exists(collectionFolderPath)) {
|
while (exportService.exists(collectionFolderPath)) {
|
||||||
collectionFolderPath = `${dir}/${sanitizeName(
|
collectionFolderPath = `${dir}/${sanitizeName(
|
||||||
collectionName
|
collection.name
|
||||||
)}(${count})`;
|
)}(${count})`;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -180,8 +183,12 @@ export const getMetadataFolderPath = (collectionFolderPath: string) =>
|
||||||
|
|
||||||
export const getUniqueFileSaveName = (
|
export const getUniqueFileSaveName = (
|
||||||
collectionPath: string,
|
collectionPath: string,
|
||||||
filename: string
|
filename: string,
|
||||||
|
fileID: number
|
||||||
) => {
|
) => {
|
||||||
|
if (exportService.isOldClient()) {
|
||||||
|
return getOldFileSaveName(filename, fileID);
|
||||||
|
}
|
||||||
let fileSaveName = sanitizeName(filename);
|
let fileSaveName = sanitizeName(filename);
|
||||||
let count = 1;
|
let count = 1;
|
||||||
while (
|
while (
|
||||||
|
@ -198,6 +205,9 @@ export const getUniqueFileSaveName = (
|
||||||
return fileSaveName;
|
return fileSaveName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getOldFileSaveName = (filename: string, fileID: number) =>
|
||||||
|
`${fileID}_${oldSanitizeName(filename)}`;
|
||||||
|
|
||||||
export const getFileMetadataSavePath = (
|
export const getFileMetadataSavePath = (
|
||||||
collectionFolderPath: string,
|
collectionFolderPath: string,
|
||||||
fileSaveName: string
|
fileSaveName: string
|
||||||
|
|
Loading…
Reference in a new issue