fix: resolve multi-instance capability in proxy routes (fixes #33)
This commit is contained in:
@@ -4,6 +4,16 @@ const axios = require('axios');
|
||||
const router = express.Router();
|
||||
const requireAuth = require('../middleware/requireAuth');
|
||||
const sanitizeError = require('../utils/sanitizeError');
|
||||
const { getSABnzbdInstances } = require('../utils/config');
|
||||
|
||||
// Helper to get first SABnzbd instance
|
||||
function getFirstSABnzbdInstance() {
|
||||
const instances = getSABnzbdInstances();
|
||||
if (!instances || instances.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return instances[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
@@ -32,11 +42,15 @@ router.use(requireAuth);
|
||||
|
||||
// GET /api/sabnzbd/queue
|
||||
router.get('/queue', async (req, res) => {
|
||||
const instance = getFirstSABnzbdInstance();
|
||||
if (!instance) {
|
||||
return res.status(503).json({ error: 'SABnzbd not configured' });
|
||||
}
|
||||
try {
|
||||
const response = await axios.get(`${process.env.SABNZBD_URL}/api`, {
|
||||
const response = await axios.get(`${instance.url}/api`, {
|
||||
params: {
|
||||
mode: 'queue',
|
||||
apikey: process.env.SABNZBD_API_KEY,
|
||||
apikey: instance.apiKey,
|
||||
output: 'json'
|
||||
}
|
||||
});
|
||||
@@ -72,11 +86,15 @@ router.get('/queue', async (req, res) => {
|
||||
*/
|
||||
// GET /api/sabnzbd/history
|
||||
router.get('/history', async (req, res) => {
|
||||
const instance = getFirstSABnzbdInstance();
|
||||
if (!instance) {
|
||||
return res.status(503).json({ error: 'SABnzbd not configured' });
|
||||
}
|
||||
try {
|
||||
const response = await axios.get(`${process.env.SABNZBD_URL}/api`, {
|
||||
const response = await axios.get(`${instance.url}/api`, {
|
||||
params: {
|
||||
mode: 'history',
|
||||
apikey: process.env.SABNZBD_API_KEY,
|
||||
apikey: instance.apiKey,
|
||||
output: 'json',
|
||||
limit: req.query.limit || 50
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user