chore(server): simplify preview extraction (#28250)

This commit is contained in:
Mert
2026-05-06 09:32:19 -04:00
committed by GitHub
parent c5c59ed040
commit 0f00053bb1
+13 -27
View File
@@ -77,34 +77,20 @@ export class MediaRepository {
* @returns ExtractResult if succeeded, or null if failed * @returns ExtractResult if succeeded, or null if failed
*/ */
async extract(input: string): Promise<ExtractResult | null> { async extract(input: string): Promise<ExtractResult | null> {
try { for (const { tag, format } of [
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw2', input); { tag: 'JpgFromRaw2', format: RawExtractedFormat.Jpeg },
return { buffer, format: RawExtractedFormat.Jpeg }; { tag: 'JpgFromRaw', format: RawExtractedFormat.Jpeg },
} catch (error: any) { { tag: 'PreviewJXL', format: RawExtractedFormat.Jxl },
this.logger.debug(`Could not extract JpgFromRaw2 buffer from image, trying JPEG from RAW next: ${error}`); { tag: 'PreviewImage', format: RawExtractedFormat.Jpeg },
} ]) {
try {
try { const buffer = await exiftool.extractBinaryTagToBuffer(tag, input);
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw', input); return { buffer, format };
return { buffer, format: RawExtractedFormat.Jpeg }; } catch (error: any) {
} catch (error: any) { this.logger.debug(`Could not extract ${tag} buffer from image: ${error}`);
this.logger.debug(`Could not extract JPEG buffer from image, trying PreviewJXL next: ${error}`); }
}
try {
const buffer = await exiftool.extractBinaryTagToBuffer('PreviewJXL', input);
return { buffer, format: RawExtractedFormat.Jxl };
} catch (error: any) {
this.logger.debug(`Could not extract PreviewJXL buffer from image, trying PreviewImage next: ${error}`);
}
try {
const buffer = await exiftool.extractBinaryTagToBuffer('PreviewImage', input);
return { buffer, format: RawExtractedFormat.Jpeg };
} catch (error: any) {
this.logger.debug(`Could not extract preview buffer from image: ${error}`);
return null;
} }
return null;
} }
async writeExif(tags: Partial<Exif>, output: string): Promise<boolean> { async writeExif(tags: Partial<Exif>, output: string): Promise<boolean> {