Skip to content

Commit

Permalink
Fix Asset Regenerate Metadata Task
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcibotari committed Feb 4, 2025
1 parent 4f1fbd2 commit f982e76
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions functions/src/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ export async function updateMetadataByRef(assetRef: DocumentReference): Promise<
inProgress: FieldValue.delete(),
updatedAt: FieldValue.serverTimestamp(),
};
if (asset.kind === AssetKind.FILE) {
if (asset.kind === AssetKind.FILE && (asset.type.startsWith('image/') || asset.type.startsWith('video/'))) {
const tempFilePath = `${os.tmpdir()}/assets-tmp`;
await bucket.file(storagePath).download({ destination: tempFilePath });
if (asset.type.startsWith('image/')) {
// Image
const [file] = await bucket.file(storagePath).download();
const { size, width, height, format, pages, isProgressive } = await sharp(file).metadata();
const { size, width, height, format, pages, isProgressive } = await sharp(tempFilePath).metadata();
if (size) {
update.size = size;
}
Expand Down Expand Up @@ -166,8 +167,6 @@ export async function updateMetadataByRef(assetRef: DocumentReference): Promise<
}
} else if (asset.type.startsWith('video/')) {
// Video
const tempFilePath = `${os.tmpdir()}/assets-tmp`;
await bucket.file(storagePath).download({ destination: tempFilePath });
const metadata = await exiftool.read(tempFilePath);
const { FileTypeExtension, Duration, ImageWidth, ImageHeight } = metadata;
update.metadata = {
Expand Down

0 comments on commit f982e76

Please sign in to comment.