mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-24 02:39:18 -05:00
* refactor: switch ExternalAPI to Fetch API * fix: add missing auth token in Plex request * fix: send proper URL params * ci: try to fix format checker * ci: ci: try to fix format checker * ci: try to fix format checker * refactor: make tautulli use the ExternalAPI class * refactor: add rate limit to fetch api * refactor: add rate limit to fetch api * refactor: switch server from axios to fetch api * refactor: switch frontend from axios to fetch api * fix: switch from URL objects to strings * fix: use the right search params for ExternalAPI * fix: better log for ExternalAPI errors * feat: add retry to external API requests * fix: try to fix network errors with IPv6 * fix: imageProxy rate limit * revert: remove retry to external API requests * feat: set IPv4 first as an option * fix(jellyfinapi): add missing argument in JellyfinAPI constructor * refactor: clean the rate limit utility
39 lines
1003 B
TypeScript
39 lines
1003 B
TypeScript
import ImageProxy from '@server/lib/imageproxy';
|
|
import logger from '@server/logger';
|
|
import { Router } from 'express';
|
|
|
|
const router = Router();
|
|
const tmdbImageProxy = new ImageProxy('tmdb', 'https://image.tmdb.org', {
|
|
rateLimitOptions: {
|
|
maxRPS: 50,
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Image Proxy
|
|
*/
|
|
router.get('/*', async (req, res) => {
|
|
const imagePath = req.path.replace('/image', '');
|
|
try {
|
|
const imageData = await tmdbImageProxy.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 image', {
|
|
imagePath,
|
|
errorMessage: e.message,
|
|
});
|
|
res.status(500).send();
|
|
}
|
|
});
|
|
|
|
export default router;
|