1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

fix(server): delete fullsize preview image on thumbnail regen after fullsize preview turned off

This commit is contained in:
Eli Gao 2024-12-25 04:49:56 +08:00
parent 132e23b058
commit fe65c44cbc
4 changed files with 11 additions and 0 deletions

View file

@ -197,4 +197,5 @@ export interface IAssetRepository {
getChangedDeltaSync(options: AssetDeltaSyncOptions): Promise<AssetEntity[]>;
upsertFile(file: UpsertFileOptions): Promise<void>;
upsertFiles(files: UpsertFileOptions[]): Promise<void>;
deleteFiles(assetIds: string | string[]): Promise<void>;
}

View file

@ -726,4 +726,9 @@ export class AssetRepository implements IAssetRepository {
async upsertFiles(files: { assetId: string; type: AssetFileType; path: string }[]): Promise<void> {
await this.fileRepository.upsert(files, { conflictPaths: ['assetId', 'type'] });
}
@GenerateSql({ params: [[DummyValue.UUID, DummyValue.UUID]] })
async deleteFiles(assetIds: string | string[]): Promise<void> {
await this.fileRepository.delete(assetIds);
}
}

View file

@ -209,6 +209,10 @@ export class MediaService extends BaseService {
if (fullsizeFile && fullsizeFile.path !== generated.fullsizePath) {
this.logger.debug(`Deleting old fullsize preview image for asset ${asset.id}`);
pathsToDelete.push(fullsizeFile.path);
if (!generated.fullsizePath) {
// did not generate a new fullsize image, delete the existing record
await this.assetRepository.deleteFiles(fullsizeFile.id);
}
}
if (pathsToDelete.length > 0) {

View file

@ -38,5 +38,6 @@ export const newAssetRepositoryMock = (): Mocked<IAssetRepository> => {
getDuplicates: vitest.fn(),
upsertFile: vitest.fn(),
upsertFiles: vitest.fn(),
deleteFiles: vitest.fn(),
};
};