mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
fix: always serve edited version if using shared link. (#25536)
* fix: always serve edited version if using shared link. * chore: test * chore: rename tests
This commit is contained in:
parent
cf6c7f9960
commit
42b354c302
2 changed files with 59 additions and 0 deletions
|
|
@ -572,6 +572,35 @@ describe(AssetMediaService.name, () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return the unedited version if requested using a shared link', async () => {
|
||||||
|
const editedAsset = {
|
||||||
|
...assetStub.withCropEdit,
|
||||||
|
files: [
|
||||||
|
...assetStub.withCropEdit.files,
|
||||||
|
{
|
||||||
|
id: 'edited-file',
|
||||||
|
type: AssetFileType.FullSize,
|
||||||
|
path: '/uploads/user-id/fullsize/edited.jpg',
|
||||||
|
isEdited: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
mocks.access.asset.checkSharedLinkAccess.mockResolvedValue(new Set([assetStub.image.id]));
|
||||||
|
mocks.asset.getForOriginal.mockResolvedValue({
|
||||||
|
...editedAsset,
|
||||||
|
editedPath: '/uploads/user-id/fullsize/edited.jpg',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(sut.downloadOriginal(authStub.adminSharedLink, 'asset-id', { edited: false })).resolves.toEqual(
|
||||||
|
new ImmichFileResponse({
|
||||||
|
path: '/uploads/user-id/fullsize/edited.jpg',
|
||||||
|
fileName: 'asset-id.jpg',
|
||||||
|
contentType: 'image/jpeg',
|
||||||
|
cacheControl: CacheControl.PrivateWithCache,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should download original file when edited=false', async () => {
|
it('should download original file when edited=false', async () => {
|
||||||
const editedAsset = {
|
const editedAsset = {
|
||||||
...assetStub.withCropEdit,
|
...assetStub.withCropEdit,
|
||||||
|
|
@ -711,6 +740,28 @@ describe(AssetMediaService.name, () => {
|
||||||
);
|
);
|
||||||
expect(mocks.asset.getForThumbnail).toHaveBeenCalledWith(assetStub.image.id, AssetFileType.Thumbnail, false);
|
expect(mocks.asset.getForThumbnail).toHaveBeenCalledWith(assetStub.image.id, AssetFileType.Thumbnail, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not return the unedited version if requested using a shared link', async () => {
|
||||||
|
mocks.access.asset.checkSharedLinkAccess.mockResolvedValue(new Set([assetStub.image.id]));
|
||||||
|
mocks.asset.getForThumbnail.mockResolvedValue({
|
||||||
|
...assetStub.image,
|
||||||
|
path: '/uploads/user-id/thumbs/edited-thumbnail.jpg',
|
||||||
|
});
|
||||||
|
await expect(
|
||||||
|
sut.viewThumbnail(authStub.adminSharedLink, assetStub.image.id, {
|
||||||
|
size: AssetMediaSize.THUMBNAIL,
|
||||||
|
edited: true,
|
||||||
|
}),
|
||||||
|
).resolves.toEqual(
|
||||||
|
new ImmichFileResponse({
|
||||||
|
path: '/uploads/user-id/thumbs/edited-thumbnail.jpg',
|
||||||
|
cacheControl: CacheControl.PrivateWithCache,
|
||||||
|
contentType: 'image/jpeg',
|
||||||
|
fileName: 'asset-id_thumbnail.jpg',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(mocks.asset.getForThumbnail).toHaveBeenCalledWith(assetStub.image.id, AssetFileType.Thumbnail, true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('playbackVideo', () => {
|
describe('playbackVideo', () => {
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,10 @@ export class AssetMediaService extends BaseService {
|
||||||
async downloadOriginal(auth: AuthDto, id: string, dto: AssetDownloadOriginalDto): Promise<ImmichFileResponse> {
|
async downloadOriginal(auth: AuthDto, id: string, dto: AssetDownloadOriginalDto): Promise<ImmichFileResponse> {
|
||||||
await this.requireAccess({ auth, permission: Permission.AssetDownload, ids: [id] });
|
await this.requireAccess({ auth, permission: Permission.AssetDownload, ids: [id] });
|
||||||
|
|
||||||
|
if (auth.sharedLink) {
|
||||||
|
dto.edited = true;
|
||||||
|
}
|
||||||
|
|
||||||
const { originalPath, originalFileName, editedPath } = await this.assetRepository.getForOriginal(
|
const { originalPath, originalFileName, editedPath } = await this.assetRepository.getForOriginal(
|
||||||
id,
|
id,
|
||||||
dto.edited ?? false,
|
dto.edited ?? false,
|
||||||
|
|
@ -222,6 +226,10 @@ export class AssetMediaService extends BaseService {
|
||||||
throw new BadRequestException('May not request original file');
|
throw new BadRequestException('May not request original file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auth.sharedLink) {
|
||||||
|
dto.edited = true;
|
||||||
|
}
|
||||||
|
|
||||||
const size = (dto.size ?? AssetMediaSize.THUMBNAIL) as unknown as AssetFileType;
|
const size = (dto.size ?? AssetMediaSize.THUMBNAIL) as unknown as AssetFileType;
|
||||||
const { originalPath, originalFileName, path } = await this.assetRepository.getForThumbnail(
|
const { originalPath, originalFileName, path } = await this.assetRepository.getForThumbnail(
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue