mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
refactor(server): use better algorithm for calculating the duplicate filename (#3061)
This commit is contained in:
parent
b93bbc9f5d
commit
19cc94e594
@ -96,19 +96,17 @@ export class AssetService {
|
||||
|
||||
const zip = this.storageRepository.createZipStream();
|
||||
const assets = await this.assetRepository.getByIds(dto.assetIds);
|
||||
const paths: Record<string, boolean> = {};
|
||||
const paths: Record<string, number> = {};
|
||||
|
||||
for (const { originalPath, originalFileName } of assets) {
|
||||
const ext = extname(originalPath);
|
||||
let filename = `${originalFileName}${ext}`;
|
||||
for (let i = 0; i < 10_000; i++) {
|
||||
if (!paths[filename]) {
|
||||
break;
|
||||
}
|
||||
filename = `${originalFileName}+${i + 1}${ext}`;
|
||||
const count = paths[filename] || 0;
|
||||
paths[filename] = count + 1;
|
||||
if (count !== 0) {
|
||||
filename = `${originalFileName}+${count}${ext}`;
|
||||
}
|
||||
|
||||
paths[filename] = true;
|
||||
zip.addFile(originalPath, filename);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user