fix(server): use preview path for person thumbnails from videos (#18419)

use preview path for person thumbnails from videos
This commit is contained in:
Mert 2025-05-21 12:15:30 -04:00 committed by GitHub
parent 188188a844
commit 493b9b7a54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 4 deletions

View File

@ -941,6 +941,48 @@ describe(MediaService.name, () => {
});
});
it('should use preview path if video', async () => {
mocks.person.getDataForThumbnailGenerationJob.mockResolvedValue(personThumbnailStub.videoThumbnail);
mocks.media.generateThumbnail.mockResolvedValue();
const data = Buffer.from('');
const info = { width: 1000, height: 1000 } as OutputInfo;
mocks.media.decodeImage.mockResolvedValue({ data, info });
await expect(sut.handleGeneratePersonThumbnail({ id: personStub.primaryPerson.id })).resolves.toBe(
JobStatus.SUCCESS,
);
expect(mocks.person.getDataForThumbnailGenerationJob).toHaveBeenCalledWith(personStub.primaryPerson.id);
expect(mocks.storage.mkdirSync).toHaveBeenCalledWith('upload/thumbs/admin_id/pe/rs');
expect(mocks.media.decodeImage).toHaveBeenCalledWith(personThumbnailStub.newThumbnailMiddle.previewPath, {
colorspace: Colorspace.P3,
orientation: undefined,
processInvalidImages: false,
});
expect(mocks.media.generateThumbnail).toHaveBeenCalledWith(
data,
{
colorspace: Colorspace.P3,
format: ImageFormat.JPEG,
quality: 80,
crop: {
left: 238,
top: 163,
width: 274,
height: 274,
},
raw: info,
processInvalidImages: false,
size: 250,
},
'upload/thumbs/admin_id/pe/rs/person-1.jpeg',
);
expect(mocks.person.update).toHaveBeenCalledWith({
id: 'person-1',
thumbnailPath: 'upload/thumbs/admin_id/pe/rs/person-1.jpeg',
});
});
it('should generate a thumbnail without going negative', async () => {
mocks.person.getDataForThumbnailGenerationJob.mockResolvedValue(personThumbnailStub.newThumbnailStart);
mocks.media.generateThumbnail.mockResolvedValue();

View File

@ -328,15 +328,13 @@ export class MediaService extends BaseService {
const { ownerId, x1, y1, x2, y2, oldWidth, oldHeight, exifOrientation, previewPath, originalPath } = data;
let inputImage: string | Buffer;
if (mimeTypes.isVideo(originalPath)) {
if (data.type === AssetType.VIDEO) {
if (!previewPath) {
this.logger.error(`Could not generate person thumbnail for video ${id}: missing preview path`);
return JobStatus.FAILED;
}
inputImage = previewPath;
}
if (image.extractEmbedded && mimeTypes.isRaw(originalPath)) {
} else if (image.extractEmbedded && mimeTypes.isRaw(originalPath)) {
const extracted = await this.extractImage(originalPath, image.preview.size);
inputImage = extracted ? extracted.buffer : originalPath;
} else {

View File

@ -246,4 +246,17 @@ export const personThumbnailStub = {
exifOrientation: '1',
previewPath: previewFile.path,
}),
videoThumbnail: Object.freeze({
ownerId: userStub.admin.id,
x1: 100,
y1: 100,
x2: 200,
y2: 200,
oldHeight: 500,
oldWidth: 400,
type: AssetType.VIDEO,
originalPath: '/original/path.mp4',
exifOrientation: '1',
previewPath: previewFile.path,
}),
};