1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-06 11:56:46 +01:00

refactor(server): use better algorithm for calculating the duplicate filename (#3061)

This commit is contained in:
Jason Rasmussen 2023-07-01 00:44:55 -04:00 committed by GitHub
parent b93bbc9f5d
commit 19cc94e594
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,19 +96,17 @@ export class AssetService {
const zip = this.storageRepository.createZipStream(); const zip = this.storageRepository.createZipStream();
const assets = await this.assetRepository.getByIds(dto.assetIds); const assets = await this.assetRepository.getByIds(dto.assetIds);
const paths: Record<string, boolean> = {}; const paths: Record<string, number> = {};
for (const { originalPath, originalFileName } of assets) { for (const { originalPath, originalFileName } of assets) {
const ext = extname(originalPath); const ext = extname(originalPath);
let filename = `${originalFileName}${ext}`; let filename = `${originalFileName}${ext}`;
for (let i = 0; i < 10_000; i++) { const count = paths[filename] || 0;
if (!paths[filename]) { paths[filename] = count + 1;
break; if (count !== 0) {
} filename = `${originalFileName}+${count}${ext}`;
filename = `${originalFileName}+${i + 1}${ext}`;
} }
paths[filename] = true;
zip.addFile(originalPath, filename); zip.addFile(originalPath, filename);
} }