Refactor arr routes: explicit dependency injection
- Updated all arr route modules to use destructured dependencies - Added JSDoc comments for factory functions - Replaced ctx. references with direct parameter access - Updated arr/index.js to extract and pass explicit dependencies - Maintained backward compatibility with context pattern - All files pass syntax validation Files refactored: - routes/arr/detect.js - routes/arr/credentials.js - routes/arr/config.js (579 lines) - routes/arr/smart-connect.js - routes/arr/plex.js - routes/arr/helpers.js - routes/arr/index.js (orchestrator)
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
const express = require('express');
|
||||
const { APP_PORTS } = require('../../constants');
|
||||
|
||||
module.exports = function(ctx, helpers) {
|
||||
/**
|
||||
* Plex routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Function} deps.fetchT - Timeout-wrapped fetch
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Function} deps.errorResponse - Error response helper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @param {Object} deps.helpers - Arr helpers module
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ fetchT, asyncHandler, errorResponse, log, helpers }) {
|
||||
const router = express.Router();
|
||||
|
||||
// Plex Libraries endpoint
|
||||
router.get('/plex/libraries', ctx.asyncHandler(async (req, res) => {
|
||||
router.get('/plex/libraries', asyncHandler(async (req, res) => {
|
||||
// Get Plex token
|
||||
let plexToken = await helpers.getPlexToken('plex');
|
||||
if (!plexToken) {
|
||||
@@ -13,7 +23,7 @@ module.exports = function(ctx, helpers) {
|
||||
}
|
||||
|
||||
if (!plexToken) {
|
||||
return ctx.errorResponse(res, 400, 'No Plex token available. Claim your Plex server first.', {
|
||||
return errorResponse(res, 400, 'No Plex token available. Claim your Plex server first.', {
|
||||
hint: 'Deploy Plex with a claim token or manually configure it.'
|
||||
});
|
||||
}
|
||||
@@ -30,13 +40,13 @@ module.exports = function(ctx, helpers) {
|
||||
} catch (e) { /* use default */ }
|
||||
|
||||
// Fetch libraries
|
||||
const libRes = await ctx.fetchT(`${plexUrl}/library/sections`, {
|
||||
const libRes = await fetchT(`${plexUrl}/library/sections`, {
|
||||
headers: { 'X-Plex-Token': plexToken, 'Accept': 'application/json' },
|
||||
signal: AbortSignal.timeout(10000)
|
||||
});
|
||||
|
||||
if (!libRes.ok) {
|
||||
return ctx.errorResponse(res, 502, `Plex returned ${libRes.status}`);
|
||||
return errorResponse(res, 502, `Plex returned ${libRes.status}`);
|
||||
}
|
||||
|
||||
const data = await libRes.json();
|
||||
@@ -52,7 +62,7 @@ module.exports = function(ctx, helpers) {
|
||||
let serverName = 'Plex';
|
||||
let version = null;
|
||||
try {
|
||||
const identityRes = await ctx.fetchT(`${plexUrl}/identity`, {
|
||||
const identityRes = await fetchT(`${plexUrl}/identity`, {
|
||||
headers: { 'X-Plex-Token': plexToken, 'Accept': 'application/json' },
|
||||
signal: AbortSignal.timeout(5000)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user