refactor(server): person thumbnail job (#4233)
* refactor(server): person thumbnail job * fix(server): set feature photo
This commit is contained in:
@@ -249,7 +249,9 @@ describe(PersonService.name, () => {
|
||||
|
||||
it("should update a person's thumbnailPath", async () => {
|
||||
personMock.getById.mockResolvedValue(personStub.withName);
|
||||
personMock.update.mockResolvedValue(personStub.withName);
|
||||
personMock.getFaceById.mockResolvedValue(faceStub.face1);
|
||||
accessMock.asset.hasOwnerAccess.mockResolvedValue(true);
|
||||
accessMock.person.hasOwnerAccess.mockResolvedValue(true);
|
||||
|
||||
await expect(
|
||||
@@ -257,25 +259,12 @@ describe(PersonService.name, () => {
|
||||
).resolves.toEqual(responseDto);
|
||||
|
||||
expect(personMock.getById).toHaveBeenCalledWith('person-1');
|
||||
expect(personMock.update).toHaveBeenCalledWith({ id: 'person-1', faceAssetId: faceStub.face1.assetId });
|
||||
expect(personMock.getFaceById).toHaveBeenCalledWith({
|
||||
assetId: faceStub.face1.assetId,
|
||||
personId: 'person-1',
|
||||
});
|
||||
expect(jobMock.queue).toHaveBeenCalledWith({
|
||||
name: JobName.GENERATE_FACE_THUMBNAIL,
|
||||
data: {
|
||||
assetId: faceStub.face1.assetId,
|
||||
personId: 'person-1',
|
||||
boundingBox: {
|
||||
x1: faceStub.face1.boundingBoxX1,
|
||||
x2: faceStub.face1.boundingBoxX2,
|
||||
y1: faceStub.face1.boundingBoxY1,
|
||||
y2: faceStub.face1.boundingBoxY2,
|
||||
},
|
||||
imageHeight: faceStub.face1.imageHeight,
|
||||
imageWidth: faceStub.face1.imageWidth,
|
||||
},
|
||||
});
|
||||
expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.GENERATE_PERSON_THUMBNAIL, data: { id: 'person-1' } });
|
||||
expect(accessMock.person.hasOwnerAccess).toHaveBeenCalledWith(authStub.admin.id, 'person-1');
|
||||
});
|
||||
|
||||
|
||||
@@ -77,8 +77,10 @@ export class PersonService {
|
||||
await this.access.requirePermission(authUser, Permission.PERSON_WRITE, id);
|
||||
let person = await this.findOrFail(id);
|
||||
|
||||
if (dto.name !== undefined || dto.birthDate !== undefined || dto.isHidden !== undefined) {
|
||||
person = await this.repository.update({ id, name: dto.name, birthDate: dto.birthDate, isHidden: dto.isHidden });
|
||||
const { name, birthDate, isHidden, featureFaceAssetId: assetId } = dto;
|
||||
|
||||
if (name !== undefined || birthDate !== undefined || isHidden !== undefined) {
|
||||
person = await this.repository.update({ id, name, birthDate, isHidden });
|
||||
if (this.needsSearchIndexUpdate(dto)) {
|
||||
const assets = await this.repository.getAssets(id);
|
||||
const ids = assets.map((asset) => asset.id);
|
||||
@@ -86,28 +88,15 @@ export class PersonService {
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.featureFaceAssetId) {
|
||||
const assetId = dto.featureFaceAssetId;
|
||||
if (assetId) {
|
||||
await this.access.requirePermission(authUser, Permission.ASSET_READ, assetId);
|
||||
const face = await this.repository.getFaceById({ personId: id, assetId });
|
||||
if (!face) {
|
||||
throw new BadRequestException('Invalid assetId for feature face');
|
||||
}
|
||||
|
||||
await this.jobRepository.queue({
|
||||
name: JobName.GENERATE_FACE_THUMBNAIL,
|
||||
data: {
|
||||
personId: id,
|
||||
assetId,
|
||||
boundingBox: {
|
||||
x1: face.boundingBoxX1,
|
||||
x2: face.boundingBoxX2,
|
||||
y1: face.boundingBoxY1,
|
||||
y2: face.boundingBoxY2,
|
||||
},
|
||||
imageHeight: face.imageHeight,
|
||||
imageWidth: face.imageWidth,
|
||||
},
|
||||
});
|
||||
person = await this.repository.update({ id, faceAssetId: assetId });
|
||||
await this.jobRepository.queue({ name: JobName.GENERATE_PERSON_THUMBNAIL, data: { id } });
|
||||
}
|
||||
|
||||
return mapPerson(person);
|
||||
|
||||
Reference in New Issue
Block a user