mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-01 12:18:35 -05:00
* refactor: proxy and cache user avatar images * fix: extract keys * fix: set avatar image URL * fix: show the correct avatar in the list of available users in advanced request * fix(s): set correct src URL for cached image * fix: remove unexpired unused image when a user changes their avatar * fix: requested changes * refactor: use 'mime' package to detmerine file extension * style: grammar * refactor: checks if the default avatar is cached to avoid creating duplicates for different users * fix: fix vulnerability * fix: fix incomplete URL substring sanitization * refactor: only cache avatar with http url protocol * fix: remove log and correctly set the if statement for the cached image component * fix: avatar images not showing on issues page * style: formatting --------- Co-authored-by: JoaquinOlivero <joaquin.olivero@hotmail.com>
33 lines
941 B
TypeScript
33 lines
941 B
TypeScript
import ImageProxy from '@server/lib/imageproxy';
|
|
import logger from '@server/logger';
|
|
import { Router } from 'express';
|
|
|
|
const router = Router();
|
|
|
|
const avatarImageProxy = new ImageProxy('avatar', '');
|
|
// Proxy avatar images
|
|
router.get('/*', async (req, res) => {
|
|
const imagePath = req.url.startsWith('/') ? req.url.slice(1) : req.url;
|
|
|
|
try {
|
|
const imageData = await avatarImageProxy.getImage(imagePath);
|
|
|
|
res.writeHead(200, {
|
|
'Content-Type': `image/${imageData.meta.extension}`,
|
|
'Content-Length': imageData.imageBuffer.length,
|
|
'Cache-Control': `public, max-age=${imageData.meta.curRevalidate}`,
|
|
'OS-Cache-Key': imageData.meta.cacheKey,
|
|
'OS-Cache-Status': imageData.meta.cacheMiss ? 'MISS' : 'HIT',
|
|
});
|
|
|
|
res.end(imageData.imageBuffer);
|
|
} catch (e) {
|
|
logger.error('Failed to proxy avatar image', {
|
|
imagePath,
|
|
errorMessage: e.message,
|
|
});
|
|
}
|
|
});
|
|
|
|
export default router;
|