u
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user