Skip to content

High performance self-hosted photo and video management solution.

fix: unsafe cast (#17590)

Daniel Dietzler270d178a2eae
diff --git a/server/src/services/asset-media.service.spec.ts b/server/src/services/asset-media.service.spec.ts
index bcaeb925b8..0c1bbc3cee 100644
--- a/server/src/services/asset-media.service.spec.ts
+++ b/server/src/services/asset-media.service.spec.ts
@@ -663,7 +663,7 @@ describe(AssetMediaService.name, () => {
});
describe('replaceAsset', () => {
- it('should error when update photo does not exist', async () => {
+ it('should fail the auth check when update photo does not exist', async () => {
await expect(sut.replaceAsset(authStub.user1, 'id', replaceDto, fileStub.photo)).rejects.toThrow(
'Not found or no asset.update access',
);
@@ -671,6 +671,15 @@ describe(AssetMediaService.name, () => {
expect(mocks.asset.create).not.toHaveBeenCalled();
});
+ it('should fail if asset cannot be fetched', async () => {
+ mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([existingAsset.id]));
+ await expect(sut.replaceAsset(authStub.user1, existingAsset.id, replaceDto, fileStub.photo)).rejects.toThrow(
+ 'Asset not found',
+ );
+
+ expect(mocks.asset.create).not.toHaveBeenCalled();
+ });
+
it('should update a photo with no sidecar to photo with no sidecar', async () => {
const updatedFile = fileStub.photo;
const updatedAsset = { ...existingAsset, ...updatedFile };
diff --git a/server/src/services/asset-media.service.ts b/server/src/services/asset-media.service.ts
index 1b8a038b9c..2929950f4d 100644
--- a/server/src/services/asset-media.service.ts
+++ b/server/src/services/asset-media.service.ts
@@ -165,7 +165,11 @@ export class AssetMediaService extends BaseService {
): Promise<AssetMediaResponseDto> {
try {
await this.requireAccess({ auth, permission: Permission.ASSET_UPDATE, ids: [id] });
- const asset = (await this.assetRepository.getById(id)) as AssetEntity;
+ const asset = await this.assetRepository.getById(id);
+
+ if (!asset) {
+ throw new Error('Asset not found');
+ }
this.requireQuota(auth, file.size);