mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
chore(server): simplify preview extraction (#28250)
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user