Module-level const assignments (SONARR_API_KEY, RADARR_API_KEY, SABNZBD_API_KEY, EMBY_URL, EMBY_API_KEY) captured values at startup and would not pick up rotated credentials without a restart. Replaced all module-level captures in emby.js, sabnzbd.js, sonarr.js, radarr.js, and dashboard.js with inline process.env reads at each call site. A process restart is still needed for dotenv-loaded values but environment-injected vars (Docker, Kubernetes) are re-read live.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const axios = require('axios');
|
|
const router = express.Router();
|
|
const requireAuth = require('../middleware/requireAuth');
|
|
const sanitizeError = require('../utils/sanitizeError');
|
|
|
|
router.use(requireAuth);
|
|
|
|
// Get current queue
|
|
router.get('/queue', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${process.env.SABNZBD_URL}/api`, {
|
|
params: {
|
|
mode: 'queue',
|
|
apikey: process.env.SABNZBD_API_KEY,
|
|
output: 'json'
|
|
}
|
|
});
|
|
res.json(response.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch SABnzbd queue', details: sanitizeError(error) });
|
|
}
|
|
});
|
|
|
|
// Get history
|
|
router.get('/history', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${process.env.SABNZBD_URL}/api`, {
|
|
params: {
|
|
mode: 'history',
|
|
apikey: process.env.SABNZBD_API_KEY,
|
|
output: 'json',
|
|
limit: req.query.limit || 50
|
|
}
|
|
});
|
|
res.json(response.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch SABnzbd history', details: sanitizeError(error) });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|