improved image handling

This commit is contained in:
blaisadmin
2026-05-02 12:06:41 -04:00
parent 01541c5f5c
commit ac1afc613f
+2 -18
View File
@@ -2763,27 +2763,11 @@ app.get('/api/birds/:birdId/photo', async (req: Request, res: Response, next: Ne
const signedUrl = getSignedS3ObjectUrl({
config: s3Config,
objectKey: bird.photo_object_key,
expiresInSeconds: 60,
expiresInSeconds: 5 * 60,
});
const imageResponse = await fetch(signedUrl);
if (!imageResponse.ok) {
res.status(imageResponse.status).json({ error: 'Unable to load bird photo.' });
return;
}
const contentType = imageResponse.headers.get('content-type') || bird.photo_content_type || 'application/octet-stream';
const contentLength = imageResponse.headers.get('content-length');
const imageBuffer = Buffer.from(await imageResponse.arrayBuffer());
res.setHeader('Content-Type', contentType);
res.setHeader('Cache-Control', 'private, max-age=300');
if (contentLength) {
res.setHeader('Content-Length', contentLength);
}
res.send(imageBuffer);
res.redirect(302, signedUrl);
} catch (error) {
next(error);
}