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
+9 -23
View File
@@ -77,35 +77,21 @@ 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> {
for (const { tag, format } of [
{ tag: 'JpgFromRaw2', format: RawExtractedFormat.Jpeg },
{ tag: 'JpgFromRaw', format: RawExtractedFormat.Jpeg },
{ tag: 'PreviewJXL', format: RawExtractedFormat.Jxl },
{ tag: 'PreviewImage', format: RawExtractedFormat.Jpeg },
]) {
try { try {
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw2', input); const buffer = await exiftool.extractBinaryTagToBuffer(tag, input);
return { buffer, format: RawExtractedFormat.Jpeg }; return { buffer, format };
} catch (error: any) { } catch (error: any) {
this.logger.debug(`Could not extract JpgFromRaw2 buffer from image, trying JPEG from RAW next: ${error}`); this.logger.debug(`Could not extract ${tag} buffer from image: ${error}`);
} }
try {
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw', input);
return { buffer, format: RawExtractedFormat.Jpeg };
} catch (error: any) {
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> {
try { try {