fix(server): use storage template when downloading files

This commit is contained in:
Jonathan Jogenfors
2025-12-09 01:50:17 +01:00
parent 287f6d5c94
commit 1a48ca3bdf
5 changed files with 13 additions and 14 deletions

View File

@@ -515,7 +515,7 @@ describe(AssetMediaService.name, () => {
await expect(sut.downloadOriginal(authStub.admin, 'asset-1')).resolves.toEqual(
new ImmichFileResponse({
path: '/original/path.jpg',
fileName: 'asset-id.jpg',
fileName: 'path.jpg',
contentType: 'image/jpeg',
cacheControl: CacheControl.PrivateWithCache,
}),

View File

@@ -1,5 +1,5 @@
import { BadRequestException, Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common';
import { extname } from 'node:path';
import { basename, extname } from 'node:path';
import sanitize from 'sanitize-filename';
import { StorageCore } from 'src/cores/storage.core';
import { Asset } from 'src/database';
@@ -200,7 +200,7 @@ export class AssetMediaService extends BaseService {
return new ImmichFileResponse({
path: asset.originalPath,
fileName: asset.originalFileName,
fileName: basename(asset.originalPath),
contentType: mimeTypes.lookup(asset.originalPath),
cacheControl: CacheControl.PrivateWithCache,
});

View File

@@ -165,7 +165,7 @@ describe(DownloadService.name, () => {
stream: archiveMock.stream,
});
expect(archiveMock.addFile).toHaveBeenCalledWith('/path/to/realpath.jpg', 'IMG_123.jpg');
expect(archiveMock.addFile).toHaveBeenCalledWith('/path/to/realpath.jpg', 'symlink.jpg');
});
});

View File

@@ -1,5 +1,5 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { parse } from 'node:path';
import { basename, parse } from 'node:path';
import { StorageCore } from 'src/cores/storage.core';
import { AssetIdsDto } from 'src/dtos/asset.dto';
import { AuthDto } from 'src/dtos/auth.dto';
@@ -94,13 +94,13 @@ export class DownloadService extends BaseService {
continue;
}
const { originalPath, originalFileName } = asset;
const { originalPath } = asset;
let filename = originalFileName;
let filename = basename(originalPath);
const count = paths[filename] || 0;
paths[filename] = count + 1;
if (count !== 0) {
const parsedFilename = parse(originalFileName);
const parsedFilename = parse(filename);
filename = `${parsedFilename.name}+${count}${parsedFilename.ext}`;
}