Fix: Catalog handles APP_TEMPLATES as object map (not just array)
APP_TEMPLATES is exported as { plex: {...}, jellyfin: {...}, ... } not
an array. All three catalog endpoints now handle both formats.
This commit is contained in:
@@ -42,9 +42,11 @@ module.exports = function({ APP_TEMPLATES, asyncHandler } = {}) {
|
||||
router.get('/catalog', wrap(async (req, res) => {
|
||||
const { category, sort } = req.query;
|
||||
let apps = APP_TEMPLATES || [];
|
||||
// APP_TEMPLATES can be an array or an object map { plex: {...}, ... }
|
||||
let appArray = Array.isArray(apps) ? apps : Object.values(apps);
|
||||
|
||||
// Build catalog entries
|
||||
let entries = apps.map(t => ({
|
||||
let entries = appArray.map(t => ({
|
||||
id: t.id || t.name?.toLowerCase().replace(/\s+/g, '-'),
|
||||
name: t.name,
|
||||
description: t.description || '',
|
||||
@@ -87,7 +89,9 @@ module.exports = function({ APP_TEMPLATES, asyncHandler } = {}) {
|
||||
return errorResponse(res, 400, 'Search query (q) is required');
|
||||
}
|
||||
|
||||
const apps = (APP_TEMPLATES || []).filter(t => {
|
||||
const allApps = APP_TEMPLATES || [];
|
||||
const appArray = Array.isArray(allApps) ? allApps : Object.values(allApps);
|
||||
const apps = appArray.filter(t => {
|
||||
const name = (t.name || '').toLowerCase();
|
||||
const desc = (t.description || '').toLowerCase();
|
||||
const cat = getTemplateCategory(t).toLowerCase();
|
||||
@@ -105,7 +109,9 @@ module.exports = function({ APP_TEMPLATES, asyncHandler } = {}) {
|
||||
// GET /api/v1/catalog/:appId — get specific app details
|
||||
router.get('/catalog/:appId', wrap(async (req, res) => {
|
||||
const appId = req.params.appId;
|
||||
const app = (APP_TEMPLATES || []).find(t => {
|
||||
const allApps = APP_TEMPLATES || [];
|
||||
const appArray = Array.isArray(allApps) ? allApps : Object.values(allApps);
|
||||
const app = appArray.find(t => {
|
||||
const tid = (t.id || t.name?.toLowerCase().replace(/\s+/g, '-'));
|
||||
return tid === appId;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user