This commit is contained in:
seb
2026-09-27 18:31:36 +02:00
parent 65b4ce5098
commit e8b23db276
2 changed files with 20 additions and 11 deletions

View File

@@ -424,17 +424,8 @@ export function register(app, basePath = '') {
return res.status(400).json({ error: 'url is required' });
}
const abortController = new AbortController();
const onClose = () => abortController.abort();
req.on('close', onClose);
res.on('close', onClose);
try {
const result = await crawlAndProcessImage(rawUrl, {
signal: abortController.signal,
});
if (res.writableEnded || res.destroyed) return;
const result = await crawlAndProcessImage(rawUrl);
res.setHeader('Content-Type', 'image/avif');
res.setHeader('Content-Length', String(result.buffer.length));
@@ -442,7 +433,6 @@ export function register(app, basePath = '') {
res.setHeader('X-Image-Height', String(result.height));
return res.status(200).send(result.buffer);
} catch (err) {
if (abortController.signal.aborted || res.writableEnded || res.destroyed) return;
const message = err?.message || 'Failed to process image';
const isUpstream = message.startsWith('Failed to crawl image:');
const status = isUpstream ? 502 : 400;