Skip to content

Commit 6170d4c

Browse files
committed
fix: improve temp file cleanup in image conversion
1 parent 7e96ac2 commit 6170d4c

File tree

1 file changed

+10
-7
lines changed
  • packages/plugin-node/src/services

1 file changed

+10
-7
lines changed

packages/plugin-node/src/services/image.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,16 @@ export class ImageDescriptionService
343343
os.tmpdir(),
344344
`tmp_img_${Date.now()}.${format}`
345345
);
346-
await sharp(data).toFormat(format).toFile(tempFilePath);
347-
const { imageData, mimeType } = await this.fetchImage(tempFilePath);
348-
fs.unlinkSync(tempFilePath); // Clean up temp file
349-
return {
350-
imageData,
351-
mimeType,
352-
};
346+
try {
347+
await sharp(data).toFormat(format).toFile(tempFilePath);
348+
const { imageData, mimeType } = await this.fetchImage(tempFilePath);
349+
return {
350+
imageData,
351+
mimeType,
352+
};
353+
} finally {
354+
fs.unlinkSync(tempFilePath); // Clean up temp file
355+
}
353356
}
354357

355358
private async fetchImage(

0 commit comments

Comments
 (0)