u
This commit is contained in:
@@ -110,21 +110,20 @@ export async function handlePimage(req, res) {
|
||||
return res.status(304).end();
|
||||
}
|
||||
|
||||
let buffer = image.buffer;
|
||||
let contentType = 'image/jpeg';
|
||||
|
||||
try {
|
||||
const imageSharp = sharp(buffer);
|
||||
const imageSharp = sharp(image.buffer);
|
||||
const meta = await imageSharp.metadata();
|
||||
|
||||
let pipeline = imageSharp.resize(targetW, targetH, {
|
||||
let pipeline = imageSharp
|
||||
.resize(targetW, targetH, {
|
||||
fit: 'inside',
|
||||
withoutEnlargement: true,
|
||||
});
|
||||
})
|
||||
.flatten({ background: '#ffffff' });
|
||||
|
||||
const accept = String(req.headers.accept || '');
|
||||
const formatParam = typeof req.query.format === 'string' ? req.query.format.toLowerCase() : '';
|
||||
|
||||
let contentType = 'image/jpeg';
|
||||
if (formatParam === 'avif' || (!formatParam && accept.includes('image/avif'))) {
|
||||
pipeline = pipeline.avif({ effort: 2 });
|
||||
contentType = 'image/avif';
|
||||
@@ -139,10 +138,7 @@ export async function handlePimage(req, res) {
|
||||
contentType = 'image/jpeg';
|
||||
}
|
||||
|
||||
buffer = await pipeline.toBuffer();
|
||||
} catch (resizeErr) {
|
||||
console.warn(`[pimage] resize/convert fallback for ${rawPath}:`, resizeErr.message);
|
||||
}
|
||||
const buffer = await pipeline.toBuffer();
|
||||
|
||||
res.setHeader('Content-Type', contentType);
|
||||
res.setHeader('Content-Length', String(buffer.length));
|
||||
|
||||
Reference in New Issue
Block a user