Skip to content

Commit

Permalink
Allow negative rating (for rejected images)
Browse files Browse the repository at this point in the history
  • Loading branch information
chkuendig committed Jan 27, 2025
1 parent e5794e6 commit 6c89c0a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
14 changes: 14 additions & 0 deletions e2e/src/api/specs/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,20 @@ describe('/asset', () => {
expect(status).toEqual(200);
});

it('should set the negative rating', async () => {
const { status, body } = await request(app)
.put(`/assets/${user1Assets[0].id}`)
.set('Authorization', `Bearer ${user1.accessToken}`)
.send({ rating: -1 });
expect(body).toMatchObject({
id: user1Assets[0].id,
exifInfo: expect.objectContaining({
rating: -1,
}),
});
expect(status).toEqual(200);
});

it('should reject invalid rating', async () => {
for (const test of [{ rating: 7 }, { rating: 3.5 }, { rating: null }]) {
const { status, body } = await request(app)
Expand Down
2 changes: 1 addition & 1 deletion mobile/openapi/lib/model/asset_bulk_update_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/openapi/lib/model/update_asset_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7951,7 +7951,7 @@
},
"rating": {
"maximum": 5,
"minimum": 0,
"minimum": -1,
"type": "number"
}
},
Expand Down Expand Up @@ -12780,7 +12780,7 @@
},
"rating": {
"maximum": 5,
"minimum": 0,
"minimum": -1,
"type": "number"
}
},
Expand Down
2 changes: 1 addition & 1 deletion server/src/dtos/asset.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class UpdateAssetBase {
@Optional()
@IsInt()
@Max(5)
@Min(0)
@Min(-1)
rating?: number;
}

Expand Down
11 changes: 11 additions & 0 deletions server/src/services/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,17 @@ describe(MetadataService.name, () => {
}),
);
});
it('should handle valid negative rating value', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.image]);
mockReadTags({ Rating: -1 });

await sut.handleMetadataExtraction({ id: assetStub.image.id });
expect(assetMock.upsertExif).toHaveBeenCalledWith(
expect.objectContaining({
rating: -1,
}),
);
});
});

describe('handleQueueSidecar', () => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class MetadataService extends BaseService {
// comments
description: String(exifTags.ImageDescription || exifTags.Description || '').trim(),
profileDescription: exifTags.ProfileDescription || null,
rating: validateRange(exifTags.Rating, 0, 5),
rating: validateRange(exifTags.Rating, -1, 5),

// grouping
livePhotoCID: (exifTags.ContentIdentifier || exifTags.MediaGroupUUID) ?? null,
Expand Down

0 comments on commit 6c89c0a

Please sign in to comment.