perf(volcano): preserve source quality for inline retry images
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-02-19 04:35:46 +08:00
parent bfec61aad1
commit cbad5ee2e2

View File

@ -53,6 +53,11 @@ async function fetchImageAsDataUri(url: string): Promise<string | null> {
const inputMime = response.headers.get("content-type") || guessImageMimeTypeFromUrl(url);
// 优先保留原图,避免 base64 回退路径带来明显画质损失
if (buffer.length <= 6 * 1024 * 1024) {
return `data:${inputMime};base64,${buffer.toString("base64")}`;
}
try {
const sharp = await import("sharp");
const optimized = await sharp.default(buffer)
@ -61,7 +66,7 @@ async function fetchImageAsDataUri(url: string): Promise<string | null> {
fit: "inside",
withoutEnlargement: true,
})
.jpeg({ quality: 86, mozjpeg: true })
.jpeg({ quality: 90, mozjpeg: true })
.toBuffer();
return `data:image/jpeg;base64,${optimized.toString("base64")}`;
} catch {