#12 gif to webp convert

This commit is contained in:
2026-05-16 20:36:11 +02:00
parent bafa6954f2
commit 32499fed36

View File

@@ -235,7 +235,25 @@ export const handleCommentUpload = async (req, res) => {
}
}
const ext = cfg.mimes[actualMime] || 'bin';
let ext = cfg.mimes[actualMime] || 'bin';
// Convert GIF → animated WebP to save disk space
if (actualMime === 'image/gif') {
const webpTmpPath = tmpPath.replace(/\.tmp$/, '.webp');
try {
await queue.spawn('magick', [tmpPath, '-coalesce', '-quality', '80', webpTmpPath]);
// Replace the temp file with the converted one
await fs.unlink(tmpPath).catch(() => {});
await fs.rename(webpTmpPath, tmpPath);
actualMime = 'image/webp';
ext = 'webp';
console.log(`[COMMENT_UPLOAD] Converted GIF → WebP: ${file.filename}`);
} catch (e) {
console.warn(`[COMMENT_UPLOAD] GIF→WebP conversion failed, keeping original:`, e.message);
await fs.unlink(webpTmpPath).catch(() => {});
}
}
const filename = `${uuid}.${ext}`;
// SHA-256 checksum