Compare commits

...

11 Commits

Author SHA1 Message Date
gronod 6c3ffb9b77 merge branch 'develop' into 'main' - Release v1.7.28
Create Release / release (push) Successful in 22s
CI / Swagger Validation & Coverage (push) Successful in 1m52s
Build and Push Docker Image / build (push) Successful in 49s
CI / Security audit (push) Successful in 3m1s
CI / Tests & coverage (push) Successful in 3m38s
2026-05-27 23:26:11 +01:00
gronod a37874c553 chore: bump version to 1.7.28 and update CHANGELOG and docs
CI / Security audit (push) Successful in 1m27s
Build and Push Docker Image / build (push) Successful in 2m0s
Docs Check / Markdown lint (push) Failing after 2m0s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 2m29s
CI / Swagger Validation & Coverage (push) Successful in 3m3s
Docs Check / Mermaid diagram parse check (push) Successful in 3m24s
CI / Tests & coverage (push) Successful in 3m34s
2026-05-27 23:25:57 +01:00
gronod 5933e09652 fix: resolve missing Sonarr link button on TV request cards (fixes #58) 2026-05-27 23:25:53 +01:00
gronod 7226404221 merge branch 'develop' into 'main' - Release v1.7.27
Create Release / release (push) Successful in 37s
CI / Swagger Validation & Coverage (push) Successful in 2m5s
CI / Security audit (push) Successful in 2m59s
Build and Push Docker Image / build (push) Successful in 1m39s
CI / Tests & coverage (push) Successful in 3m48s
2026-05-27 23:11:37 +01:00
gronod 1ee2a8044b chore: bump version to 1.7.27 and update CHANGELOG and docs
Build and Push Docker Image / build (push) Successful in 1m25s
Docs Check / Markdown lint (push) Failing after 1m24s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 1m53s
Docs Check / Mermaid diagram parse check (push) Successful in 2m46s
CI / Security audit (push) Successful in 3m14s
CI / Swagger Validation & Coverage (push) Successful in 3m32s
CI / Tests & coverage (push) Successful in 3m55s
2026-05-27 23:11:23 +01:00
gronod 86277e2059 fix: serve frontend static files and handle SPA routes (fixes #57) 2026-05-27 23:11:19 +01:00
gronod 0eaa54cf4a merge branch 'develop' into 'main' - Release v1.7.26
Create Release / release (push) Successful in 8s
CI / Security audit (push) Successful in 3m0s
CI / Swagger Validation & Coverage (push) Successful in 1m57s
Build and Push Docker Image / build (push) Successful in 1m26s
CI / Tests & coverage (push) Successful in 3m37s
2026-05-27 22:50:31 +01:00
gronod 865cf1f57a chore: bump version to 1.7.26 and update CHANGELOG and docs
Build and Push Docker Image / build (push) Successful in 1m25s
Docs Check / Markdown lint (push) Failing after 1m47s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 2m12s
CI / Security audit (push) Successful in 2m54s
CI / Swagger Validation & Coverage (push) Successful in 3m7s
Docs Check / Mermaid diagram parse check (push) Successful in 3m18s
CI / Tests & coverage (push) Successful in 3m28s
2026-05-27 22:50:29 +01:00
gronod ff5f50cc3a chore: remove reg.i3omb.com from build-image workflow
Build and Push Docker Image / build (push) Successful in 58s
CI / Security audit (push) Successful in 1m43s
CI / Swagger Validation & Coverage (push) Successful in 2m6s
CI / Tests & coverage (push) Successful in 2m26s
Only publish container images to git.i3omb.com registry.
2026-05-27 21:46:34 +01:00
gronod fd0dc7528d merge branch 'develop' into 'main' - Release v1.7.25
Create Release / release (push) Successful in 23s
CI / Security audit (push) Successful in 1m49s
Build and Push Docker Image / build (push) Successful in 1m50s
CI / Swagger Validation & Coverage (push) Successful in 2m18s
CI / Tests & coverage (push) Successful in 2m30s
2026-05-27 21:43:45 +01:00
gronod 33b122d22b fix(ombi): resolve TV request status, user, and date display (Issue #53)
Build and Push Docker Image / build (push) Successful in 1m46s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 1m33s
CI / Security audit (push) Successful in 1m56s
CI / Swagger Validation & Coverage (push) Successful in 2m35s
CI / Tests & coverage (push) Successful in 2m51s
Ombi's TV API nests all request data (requestedUser, approved, available,
denied, requested, requestedDate) inside childRequests[] sub-objects.
The application previously only inspected top-level properties, causing
TV shows to consistently display 'unknown' status, 'unknown' user, and
no request date.

Changes:
- OmbiRetriever._hydrateRequest(): hydrate requestedUser on each
  childRequests entry and promote requestedDate to top level
- getRequestStatus() (server + client): aggregate status flags from
  childRequests[] when top-level properties are absent
- Client date display: fallback to childRequests[0].requestedDate
- Add 18 unit tests covering childRequests hydration, status
  aggregation, and date promotion

Closes #53
2026-05-27 21:13:17 +01:00
18 changed files with 499 additions and 375 deletions
+2 -8
View File
@@ -27,20 +27,14 @@ jobs:
if [[ "$BRANCH" == develop* ]]; then if [[ "$BRANCH" == develop* ]]; then
# Sanitise branch name for tag: replace slashes with dashes # Sanitise branch name for tag: replace slashes with dashes
SAFE_BRANCH=$(echo "$BRANCH" | tr '/' '-') SAFE_BRANCH=$(echo "$BRANCH" | tr '/' '-')
TAGS="reg.i3omb.com/sofarr:${SAFE_BRANCH}" TAGS="git.i3omb.com/gandalf/sofarr:${SAFE_BRANCH}"
TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:${SAFE_BRANCH}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "Building develop image tags: ${TAGS}" echo "Building develop image tags: ${TAGS}"
else else
RELEASE_NAME=${BRANCH#release/} RELEASE_NAME=${BRANCH#release/}
# Primary registry tags
TAGS="reg.i3omb.com/sofarr:${VERSION}"
TAGS="${TAGS},reg.i3omb.com/sofarr:${RELEASE_NAME}"
TAGS="${TAGS},reg.i3omb.com/sofarr:latest"
# Gitea package registry tags # Gitea package registry tags
TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:${VERSION}" TAGS="git.i3omb.com/gandalf/sofarr:${VERSION}"
TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:${RELEASE_NAME}" TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:${RELEASE_NAME}"
TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:latest" TAGS="${TAGS},git.i3omb.com/gandalf/sofarr:latest"
+27
View File
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.7.28] - 2026-05-27
### Fixed
- **Missing Sonarr Link on TV Requests (Issue #58)** — Resolved a bug where the Sonarr deep-link button was missing on TV request cards while Radarr links correctly appeared on movie request cards. Added support for all camelCase TVDB ID variants (`tvDbId`, `tvdbId`, `theTvdbId`, `theTvDbId`, `TvDbId`, `TheTvDbId`) on both backend link decoration (`server/utils/ombiHelpers.js`) and frontend rendering (`client/src/ui/requests.js`). Added a dedicated integration test to safeguard links decoration for TV requests.
## [1.7.27] - 2026-05-27
### Fixed
- **Frontend Dashboard Serve Regression (Issue #57)** — Resolved a critical regression where the Vite-built frontend dashboard UI was not served. Consolidated Express configurations by migrating static files serving and SPA routing into the `createApp` factory in `server/app.js`. Cleaned up `server/index.js` to import and instantiate the app from the factory, successfully eliminating over 300 lines of duplicate route and middleware registrations, and ensuring alignment between development testing and production runtime configurations.
## [1.7.26] - 2026-05-27
### Fixed
- **Missing Ombi & *Arr Request Links (Issue #56)** — Resolved an issue where the Ombi and *Arr lookup buttons failed to appear against request cards. Added `decorateRequestsWithArrLinks` to aggregate IDs and query Radarr/Sonarr libraries during SSE stream decoration and backend REST fetching. Also fixed a frontend condition failing to generate Ombi links for TV requests by checking a broader set of ID properties (`theTvDbId`, `theTmdbId`, `imdbId`).
## [1.7.25] - 2026-05-27
### Fixed
- **Ombi TV Request Status, User, and Date Resolution (Issue #53)** — Resolved the root cause where Ombi TV show requests consistently displayed "unknown" status, "unknown" user, and missing request dates. The Ombi API nests all TV request data (`requestedUser`, `approved`, `available`, `denied`, `requested`, `requestedDate`) inside `childRequests[]` sub-objects, while the application previously only inspected top-level properties.
- `OmbiRetriever._hydrateRequest()` now hydrates `requestedUser` on each `childRequests` entry and promotes `requestedDate` from `childRequests[0]` to the top level.
- `getRequestStatus()` (server and client) now aggregates status flags from `childRequests[]` when top-level properties are absent.
- Client-side date display now falls back to `childRequests[0].requestedDate` as a defensive measure.
## [1.7.24] - 2026-05-27 ## [1.7.24] - 2026-05-27
### Enhanced ### Enhanced
+5 -3
View File
@@ -158,7 +158,8 @@ function createRequestCard(request) {
} }
meta.appendChild(user); meta.appendChild(user);
const dateStr = request.requestedDate || request.RequestedDate || request.date || request.Date; const childDate = request.childRequests && request.childRequests[0] ? (request.childRequests[0].requestedDate || request.childRequests[0].RequestedDate) : null;
const dateStr = request.requestedDate || request.RequestedDate || request.date || request.Date || childDate;
if (dateStr) { if (dateStr) {
const requestDate = document.createElement('span'); const requestDate = document.createElement('span');
requestDate.className = 'request-date'; requestDate.className = 'request-date';
@@ -193,10 +194,11 @@ function createRequestCard(request) {
const actions = document.createElement('span'); const actions = document.createElement('span');
actions.className = 'service-icons-container'; actions.className = 'service-icons-container';
if (state.ombiBaseUrl && request.theMovieDbId) { const id = request.theTvDbId || request.theTvdbId || request.tvDbId || request.tvdbId || request.TvDbId || request.TheTvDbId || request.theMovieDbId || request.theTmdbId || request.imdbId || request.ImdbId;
if (state.ombiBaseUrl && id) {
const ombiLink = document.createElement('a'); const ombiLink = document.createElement('a');
ombiLink.className = 'ombi-link'; ombiLink.className = 'ombi-link';
ombiLink.href = `${state.ombiBaseUrl}/details/${request.mediaType || 'movie'}/${request.theMovieDbId}`; ombiLink.href = `${state.ombiBaseUrl}/details/${request.mediaType || 'movie'}/${id}`;
ombiLink.target = '_blank'; ombiLink.target = '_blank';
ombiLink.title = 'View in Ombi'; ombiLink.title = 'View in Ombi';
+17
View File
@@ -17,6 +17,23 @@ export function getRequestStatus(request) {
if (request.denied) return 'denied'; if (request.denied) return 'denied';
if (request.approved) return 'approved'; if (request.approved) return 'approved';
if (request.requested) return 'pending'; if (request.requested) return 'pending';
// Ombi TV requests store status flags inside childRequests
if (Array.isArray(request.childRequests) && request.childRequests.length > 0) {
for (const child of request.childRequests) {
if (child && child.available) return 'available';
}
for (const child of request.childRequests) {
if (child && child.denied) return 'denied';
}
for (const child of request.childRequests) {
if (child && child.approved) return 'approved';
}
for (const child of request.childRequests) {
if (child && child.requested) return 'pending';
}
}
return 'unknown'; return 'unknown';
} }
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "sofarr", "name": "sofarr",
"version": "1.7.24", "version": "1.7.28",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "sofarr", "name": "sofarr",
"version": "1.7.24", "version": "1.7.28",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.6.0", "axios": "^1.6.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "sofarr", "name": "sofarr",
"version": "1.7.24", "version": "1.7.28",
"description": "A personal media download dashboard that shows your downloads 'so far' while you relax on the sofa waiting for your *arr services to finish", "description": "A personal media download dashboard that shows your downloads 'so far' while you relax on the sofa waiting for your *arr services to finish",
"main": "server/index.js", "main": "server/index.js",
"scripts": { "scripts": {
+40 -1
View File
@@ -15,6 +15,7 @@ const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc'); const swaggerJsdoc = require('swagger-jsdoc');
const YAML = require('yamljs'); const YAML = require('yamljs');
const path = require('path'); const path = require('path');
const fs = require('fs');
const { version } = require('../package.json'); const { version } = require('../package.json');
const sabnzbdRoutes = require('./routes/sabnzbd'); const sabnzbdRoutes = require('./routes/sabnzbd');
@@ -132,7 +133,7 @@ function createApp({ skipRateLimits = false } = {}) {
* version: * version:
* type: string * type: string
* description: sofarr version * description: sofarr version
* example: "1.7.24" * example: "1.7.28"
* x-code-samples: * x-code-samples:
* - lang: curl * - lang: curl
* label: cURL * label: cURL
@@ -232,6 +233,44 @@ function createApp({ skipRateLimits = false } = {}) {
app.use('/api/status', statusRoutes); app.use('/api/status', statusRoutes);
app.use('/api/history', historyRoutes); app.use('/api/history', historyRoutes);
// ---------------------------------------------------------------------------
// Static files — served before API routes
// index.html is served manually so we can inject the CSP nonce
// ---------------------------------------------------------------------------
const PUBLIC_DIR = path.join(__dirname, '../public');
const INDEX_HTML = path.join(PUBLIC_DIR, 'index.html');
// Serve all static assets (js, css, images, icons) except index.html.
// JS and CSS get no-cache so browsers revalidate on every load (ETag still
// avoids re-downloading unchanged files; only a deploy changes the ETag).
app.use(express.static(PUBLIC_DIR, {
index: false,
setHeaders(res, filePath) {
if (filePath.endsWith('.js') || filePath.endsWith('.css')) {
res.setHeader('Cache-Control', 'no-cache');
}
}
}));
// Serve index.html with CSP nonce injected into <script> tags
function serveIndex(req, res) {
fs.readFile(INDEX_HTML, 'utf8', (err, html) => {
if (err) return res.status(500).send('Internal Server Error');
const nonce = res.locals.cspNonce;
// Only inject nonce into <script> tags — style-src 'self' already permits
// same-origin <link rel=stylesheet> without a nonce, and injecting a nonce
// onto <link> breaks mobile browsers / caching proxies (stale HTML carries
// the old nonce which no longer matches the per-request CSP header).
const patched = html
.replace(/<script([^>]*)>/gi, `<script nonce="${nonce}"$1>`);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.send(patched);
});
}
// SPA catch-all — serve index.html for any unmatched path
app.get('*', serveIndex);
// Global error handler // Global error handler
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
+45 -2
View File
@@ -163,6 +163,8 @@ class OmbiRetriever extends ArrRetriever {
_hydrateRequest(req) { _hydrateRequest(req) {
if (!req) return req; if (!req) return req;
let result = req;
const reqUserId = req.requestedUserId || req.RequestedUserId; const reqUserId = req.requestedUserId || req.RequestedUserId;
if (reqUserId && this.cache.userMap.has(reqUserId)) { if (reqUserId && this.cache.userMap.has(reqUserId)) {
const cachedUser = this.cache.userMap.get(reqUserId); const cachedUser = this.cache.userMap.get(reqUserId);
@@ -179,14 +181,55 @@ class OmbiRetriever extends ArrRetriever {
normalizedUserName: cachedUser.normalizedUserName || cachedUser.NormalizedUserName || '' normalizedUserName: cachedUser.normalizedUserName || cachedUser.NormalizedUserName || ''
}; };
return { result = {
...req, ...req,
requestedUser: hydratedUser, requestedUser: hydratedUser,
RequestedUser: hydratedUser RequestedUser: hydratedUser
}; };
} }
} }
return req;
// Hydrate childRequests (common for Ombi TV show requests)
if (Array.isArray(result.childRequests) && result.childRequests.length > 0) {
const hydratedChildren = result.childRequests.map(child => {
if (!child) return child;
const childUserId = child.requestedUserId || child.RequestedUserId;
if (childUserId && this.cache.userMap.has(childUserId)) {
const cachedUser = this.cache.userMap.get(childUserId);
let childUser = child.requestedUser || child.RequestedUser;
if (!childUser || typeof childUser !== 'object' || Object.keys(childUser).length === 0) {
const hydratedUser = {
id: cachedUser.id,
userName: cachedUser.userName,
alias: cachedUser.alias || cachedUser.Alias || '',
userAlias: cachedUser.userAlias || cachedUser.UserAlias || '',
normalizedUserName: cachedUser.normalizedUserName || cachedUser.NormalizedUserName || ''
};
return {
...child,
requestedUser: hydratedUser,
RequestedUser: hydratedUser
};
}
}
return child;
});
result = { ...result, childRequests: hydratedChildren };
}
// Promote requestedDate from childRequests to top level (common for Ombi TV)
if (!result.requestedDate && Array.isArray(result.childRequests) && result.childRequests.length > 0) {
const childDate = result.childRequests[0].requestedDate || result.childRequests[0].RequestedDate;
if (childDate) {
result = { ...result, requestedDate: childDate };
}
}
return result;
} }
/** /**
+2 -287
View File
@@ -82,20 +82,9 @@ console.error = function(...args) {
logFile.write(`[${new Date().toISOString()}] ERROR: ${message}\n`); logFile.write(`[${new Date().toISOString()}] ERROR: ${message}\n`);
}; };
const sabnzbdRoutes = require('./routes/sabnzbd');
const sonarrRoutes = require('./routes/sonarr');
const radarrRoutes = require('./routes/radarr');
const embyRoutes = require('./routes/emby');
const dashboardRoutes = require('./routes/dashboard');
const statusRoutes = require('./routes/status');
const historyRoutes = require('./routes/history');
const authRoutes = require('./routes/auth');
const webhookRoutes = require('./routes/webhook');
const ombiRoutes = require('./routes/ombi');
const debugRoutes = require('./routes/debug');
const verifyCsrf = require('./middleware/verifyCsrf');
const { startPoller, POLL_INTERVAL, POLLING_ENABLED } = require('./utils/poller'); const { startPoller, POLL_INTERVAL, POLLING_ENABLED } = require('./utils/poller');
const { validateInstanceUrl } = require('./utils/config'); const { validateInstanceUrl } = require('./utils/config');
const { createApp } = require('./app');
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Startup environment validation // Startup environment validation
@@ -117,284 +106,10 @@ if (process.env.EMBY_URL) {
validateInstanceUrl(process.env.EMBY_URL, 'EMBY_URL'); validateInstanceUrl(process.env.EMBY_URL, 'EMBY_URL');
} }
const app = express(); const app = createApp();
const PORT = process.env.PORT || 3001; const PORT = process.env.PORT || 3001;
// Load OpenAPI spec from YAML
const openapiSpec = YAML.load(path.join(__dirname, 'openapi.yaml'));
// Configure swagger-jsdoc to merge JSDoc comments from route files
const swaggerOptions = {
definition: {
...openapiSpec,
openapi: '3.1.0'
},
apis: [
path.join(__dirname, 'routes/*.js'),
path.join(__dirname, 'index.js')
]
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
// Resolve TLS_ENABLED early — used in Helmet CSP and server startup
const TLS_ENABLED = (process.env.TLS_ENABLED || 'true').toLowerCase() !== 'false'; const TLS_ENABLED = (process.env.TLS_ENABLED || 'true').toLowerCase() !== 'false';
// ---------------------------------------------------------------------------
// Trust proxy — required when behind Nginx/Caddy/Traefik so that
// req.ip reflects the real client IP (not 127.0.0.1) and
// req.secure is true when the upstream TLS is terminated by the proxy.
// Set TRUST_PROXY=1 (or a specific IP/CIDR) via env.
// ---------------------------------------------------------------------------
if (process.env.TRUST_PROXY) {
const trustValue = /^\d+$/.test(process.env.TRUST_PROXY)
? parseInt(process.env.TRUST_PROXY, 10)
: process.env.TRUST_PROXY;
app.set('trust proxy', trustValue);
}
// ---------------------------------------------------------------------------
// Helmet v7 — security response headers
// CSP uses a per-request nonce injected into index.html so inline scripts
// and styles are allowed only with a valid nonce, not blanket unsafe-inline.
// ---------------------------------------------------------------------------
app.use((req, res, next) => {
// Generate a fresh nonce for every request
res.locals.cspNonce = crypto.randomBytes(16).toString('base64');
next();
});
app.use((req, res, next) => {
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", (req, res) => `'nonce-${res.locals.cspNonce}'`],
styleSrc: ["'self'", (req, res) => `'nonce-${res.locals.cspNonce}'`],
imgSrc: ["'self'", 'data:', 'blob:'],
fontSrc: ["'self'", 'data:'],
connectSrc: ["'self'"],
objectSrc: ["'none'"],
baseUri: ["'self'"],
frameAncestors: ["'none'"],
formAction: ["'self'"],
upgradeInsecureRequests: (process.env.TRUST_PROXY || TLS_ENABLED) ? [] : null
}
},
hsts: {
maxAge: 31536000, // 1 year
includeSubDomains: true,
preload: true
},
referrerPolicy: { policy: 'strict-origin-when-cross-origin' },
crossOriginEmbedderPolicy: false // not needed for this SPA
})(req, res, next);
});
// Permissions-Policy — disable powerful browser features not needed by the app
app.use((req, res, next) => {
res.setHeader(
'Permissions-Policy',
'camera=(), microphone=(), geolocation=(), payment=(), usb=()'
);
next();
});
// ---------------------------------------------------------------------------
// General API rate limiter — applies to all /api/* routes
// More specific limiters (e.g. login) apply on top of this.
// ---------------------------------------------------------------------------
const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 300, // 300 requests per IP per window (generous for polling)
standardHeaders: true,
legacyHeaders: false,
skip: (req) => req.originalUrl && req.originalUrl.startsWith('/api/dashboard/cover-art'),
message: { error: 'Too many requests, please try again later' }
});
// ---------------------------------------------------------------------------
// Body parsing & cookies
// ---------------------------------------------------------------------------
app.use(cookieParser(cookieSecret || undefined));
app.use(express.json({ limit: '64kb' })); // prevent oversized JSON payloads
// ---------------------------------------------------------------------------
// Health / readiness endpoints (no auth, no rate-limit)
// Used by Docker HEALTHCHECK and orchestrators.
// ---------------------------------------------------------------------------
/**
* @openapi
* /health:
* get:
* tags: [Health]
* summary: Health check
* description: Returns server uptime and status. No authentication required. Used for liveness probes.
* security: []
* responses:
* '200':
* description: Server is healthy
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: "ok"
* uptime:
* type: number
* description: Server uptime in seconds
* example: 3600.5
* version:
* type: string
* description: sofarr version
* example: "1.7.24"
*/
app.get('/health', (req, res) => {
res.json({ status: 'ok', uptime: process.uptime(), version });
});
/**
* @openapi
* /ready:
* get:
* tags: [Health]
* summary: Readiness check
* description: Checks if critical configuration (EMBY_URL) is present. Used by Docker HEALTHCHECK and orchestrators. No authentication required.
* security: []
* responses:
* '200':
* description: Server is ready
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: "ready"
* '503':
* description: Server not ready
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: "not ready"
* reason:
* type: string
* example: "EMBY_URL not configured"
*/
app.get('/ready', (req, res) => {
// Confirm critical config is present
const ready = !!(process.env.EMBY_URL);
if (ready) {
res.json({ status: 'ready' });
} else {
res.status(503).json({ status: 'not ready', reason: 'EMBY_URL not configured' });
}
});
// ---------------------------------------------------------------------------
// Swagger UI - publicly accessible API documentation
// ---------------------------------------------------------------------------
app.use('/api/swagger', swaggerUi.serve, swaggerUi.setup(null, {
customSiteTitle: 'sofarr API Documentation',
customCss: '.swagger-ui .topbar { display: none }',
customJs: [
'/swagger-auth-banner.js'
],
swaggerOptions: {
url: '/api/swagger.json'
}
}));
// Serve the raw OpenAPI spec as JSON with dynamic server URL
app.get('/api/swagger.json', (req, res) => {
// Clone the spec to avoid modifying the original
const specCopy = JSON.parse(JSON.stringify(swaggerSpec));
// Replace the server URL with the current request's origin
if (specCopy.servers && specCopy.servers.length > 0) {
const protocol = req.protocol;
const host = req.get('host');
specCopy.servers[0].url = `${protocol}://${host}`;
}
res.json(specCopy);
});
// ---------------------------------------------------------------------------
// Static files — served before API routes
// index.html is served manually so we can inject the CSP nonce
// ---------------------------------------------------------------------------
const PUBLIC_DIR = path.join(__dirname, '../public');
const INDEX_HTML = path.join(PUBLIC_DIR, 'index.html');
// Serve all static assets (js, css, images, icons) except index.html.
// JS and CSS get no-cache so browsers revalidate on every load (ETag still
// avoids re-downloading unchanged files; only a deploy changes the ETag).
app.use(express.static(PUBLIC_DIR, {
index: false,
setHeaders(res, filePath) {
if (filePath.endsWith('.js') || filePath.endsWith('.css')) {
res.setHeader('Cache-Control', 'no-cache');
}
}
}));
// Serve index.html with CSP nonce injected into <script> tags
function serveIndex(req, res) {
fs.readFile(INDEX_HTML, 'utf8', (err, html) => {
if (err) return res.status(500).send('Internal Server Error');
const nonce = res.locals.cspNonce;
// Only inject nonce into <script> tags — style-src 'self' already permits
// same-origin <link rel=stylesheet> without a nonce, and injecting a nonce
// onto <link> breaks mobile browsers / caching proxies (stale HTML carries
// the old nonce which no longer matches the per-request CSP header).
const patched = html
.replace(/<script([^>]*)>/gi, `<script nonce="${nonce}"$1>`);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.send(patched);
});
}
// ---------------------------------------------------------------------------
// API routes (rate-limited; auth routes exempt CSRF for login/csrf endpoints)
// CSRF protection applies to all state-changing /api/* requests except
// /api/auth/login (pre-auth) and /api/auth/csrf (issues the token).
// ---------------------------------------------------------------------------
app.use('/api', apiLimiter);
app.use('/api/auth', authRoutes);
app.use('/api/webhook', webhookRoutes);
app.use('/api/debug', debugRoutes);
// All routes below this point require CSRF validation on mutating methods
app.use('/api', verifyCsrf);
app.use('/api/sabnzbd', sabnzbdRoutes);
app.use('/api/sonarr', sonarrRoutes);
app.use('/api/radarr', radarrRoutes);
app.use('/api/emby', embyRoutes);
app.use('/api/ombi', ombiRoutes);
app.use('/api/dashboard', dashboardRoutes);
app.use('/api/status', statusRoutes);
app.use('/api/history', historyRoutes);
// SPA catch-all — serve index.html for any unmatched path
app.get('*', serveIndex);
// ---------------------------------------------------------------------------
// Global error handler — never leak stack traces to clients
// ---------------------------------------------------------------------------
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
console.error('[Server] Unhandled error:', err.message);
res.status(500).json({ error: 'Internal server error' });
});
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// TLS / HTTPS support // TLS / HTTPS support
// Set TLS_CERT and TLS_KEY to paths of your certificate and private key. // Set TLS_CERT and TLS_KEY to paths of your certificate and private key.
+1 -1
View File
@@ -22,7 +22,7 @@ info:
## SSE Streaming ## SSE Streaming
Real-time updates are available via Server-Sent Events at GET /api/dashboard/stream. Real-time updates are available via Server-Sent Events at GET /api/dashboard/stream.
version: 1.7.24 version: 1.7.28
contact: contact:
name: sofarr name: sofarr
license: license:
+9 -3
View File
@@ -13,7 +13,7 @@ const { buildUserDownloads } = require('../services/DownloadBuilder');
const { onHistoryUpdate, offHistoryUpdate } = require('../utils/historyFetcher'); const { onHistoryUpdate, offHistoryUpdate } = require('../utils/historyFetcher');
const arrRetrieverRegistry = require('../utils/arrRetrievers'); const arrRetrieverRegistry = require('../utils/arrRetrievers');
const { getOmbiInstances, getSonarrInstances, getRadarrInstances } = require('../utils/config'); const { getOmbiInstances, getSonarrInstances, getRadarrInstances } = require('../utils/config');
const { extractRequestedUser, filterRequestsByUser } = require('../utils/ombiHelpers'); const { extractRequestedUser, filterRequestsByUser, decorateRequestsWithArrLinks } = require('../utils/ombiHelpers');
const { canBlocklist } = require('../services/DownloadAssembler'); const { canBlocklist } = require('../services/DownloadAssembler');
@@ -525,8 +525,14 @@ router.get('/stream', requireAuth, async (req, res) => {
const showAllOmbi = showAll; // Use the same showAll flag for Ombi const showAllOmbi = showAll; // Use the same showAll flag for Ombi
const filteredOmbiMovieRequests = filterRequestsByUser(ombiRequests.movie || [], username, showAllOmbi); const filteredOmbiMovieRequests = filterRequestsByUser(ombiRequests.movie || [], username, showAllOmbi).map(r => ({ ...r, mediaType: 'movie' }));
const filteredOmbiTvRequests = filterRequestsByUser(ombiRequests.tv || [], username, showAllOmbi); const filteredOmbiTvRequests = filterRequestsByUser(ombiRequests.tv || [], username, showAllOmbi).map(r => ({ ...r, mediaType: 'tv' }));
// Admin only: add Sonarr/Radarr lookup links
if (isAdmin) {
const allFiltered = [...filteredOmbiMovieRequests, ...filteredOmbiTvRequests];
await decorateRequestsWithArrLinks(allFiltered, isAdmin);
}
const ombiRequestsFiltered = { const ombiRequestsFiltered = {
movie: filteredOmbiMovieRequests, movie: filteredOmbiMovieRequests,
+6 -61
View File
@@ -4,7 +4,7 @@ const { logToFile } = require('../utils/logger');
const cache = require('../utils/cache'); const cache = require('../utils/cache');
const { getOmbiInstances, getWebhookSecret, getSofarrBaseUrl, getSofarrWebhookBaseUrl } = require('../utils/config'); const { getOmbiInstances, getWebhookSecret, getSofarrBaseUrl, getSofarrWebhookBaseUrl } = require('../utils/config');
const requireAuth = require('../middleware/requireAuth'); const requireAuth = require('../middleware/requireAuth');
const { extractRequestedUser, filterRequestsByUser } = require('../utils/ombiHelpers'); const { extractRequestedUser, filterRequestsByUser, decorateRequestsWithArrLinks } = require('../utils/ombiHelpers');
const { applyRequestFilters } = require('../utils/ombiFilters'); const { applyRequestFilters } = require('../utils/ombiFilters');
const router = express.Router(); const router = express.Router();
@@ -120,72 +120,17 @@ router.get('/requests', requireAuth, async (req, res) => {
const filteredMovieRequests = filterRequestsByUser(ombiRequests.movie || [], username, showAll); const filteredMovieRequests = filterRequestsByUser(ombiRequests.movie || [], username, showAll);
const filteredTvRequests = filterRequestsByUser(ombiRequests.tv || [], username, showAll); const filteredTvRequests = filterRequestsByUser(ombiRequests.tv || [], username, showAll);
// Admin only: add Sonarr/Radarr lookup links
if (isAdmin) {
const sonarrRetrievers = arrRetrieverRegistry.getRetrieversByType('sonarr') || [];
const radarrRetrievers = arrRetrieverRegistry.getRetrieversByType('radarr') || [];
// Fetch all series and movies in parallel to match
const [sonarrData, radarrData] = await Promise.all([
Promise.all(sonarrRetrievers.map(async r => {
try {
const response = await require('axios').get(`${r.url}/api/v3/series`, {
headers: { 'X-Api-Key': r.apiKey }
});
return { instance: r, series: response.data || [] };
} catch {
return { instance: r, series: [] };
}
})),
Promise.all(radarrRetrievers.map(async r => {
try {
const response = await require('axios').get(`${r.url}/api/v3/movie`, {
headers: { 'X-Api-Key': r.apiKey }
});
return { instance: r, movies: response.data || [] };
} catch {
return { instance: r, movies: [] };
}
}))
]);
// For TV requests, find match in Sonarr
filteredTvRequests.forEach(req => {
const tvdbId = req.theTvDbId || req.theMovieDbId || req.theTvdbId || req.theTmdbId || req.TvDbId || req.TheTvDbId;
if (!tvdbId) return;
for (const instData of sonarrData) {
const match = instData.series.find(s => s && (s.tvdbId === parseInt(tvdbId, 10) || s.tmdbId === parseInt(tvdbId, 10)));
if (match && match.titleSlug) {
req.arrLink = `${instData.instance.url}/series/${match.titleSlug}`;
req.arrType = 'sonarr';
break;
}
}
});
// For Movie requests, find match in Radarr
filteredMovieRequests.forEach(req => {
const tmdbId = req.theMovieDbId || req.imdbId || req.theTmdbId || req.TheMovieDbId || req.ImdbId;
if (!tmdbId) return;
for (const instData of radarrData) {
const match = instData.movies.find(m => m && (m.tmdbId === parseInt(tmdbId, 10) || m.imdbId === tmdbId));
if (match && match.titleSlug) {
req.arrLink = `${instData.instance.url}/movie/${match.titleSlug}`;
req.arrType = 'radarr';
break;
}
}
});
}
// Tag with mediaType and flatten for filtering/sorting // Tag with mediaType and flatten for filtering/sorting
const allRequests = [ const allRequests = [
...filteredMovieRequests.map(r => ({ ...r, mediaType: 'movie' })), ...filteredMovieRequests.map(r => ({ ...r, mediaType: 'movie' })),
...filteredTvRequests.map(r => ({ ...r, mediaType: 'tv' })) ...filteredTvRequests.map(r => ({ ...r, mediaType: 'tv' }))
]; ];
// Admin only: add Sonarr/Radarr lookup links
if (isAdmin) {
await decorateRequestsWithArrLinks(allRequests, isAdmin);
}
// Parse query params // Parse query params
let types = req.query.type; let types = req.query.type;
let statuses = req.query.status; let statuses = req.query.status;
+17
View File
@@ -17,6 +17,23 @@ function getRequestStatus(request) {
if (request.denied) return 'denied'; if (request.denied) return 'denied';
if (request.approved) return 'approved'; if (request.approved) return 'approved';
if (request.requested) return 'pending'; if (request.requested) return 'pending';
// Ombi TV requests store status flags inside childRequests
if (Array.isArray(request.childRequests) && request.childRequests.length > 0) {
for (const child of request.childRequests) {
if (child && child.available) return 'available';
}
for (const child of request.childRequests) {
if (child && child.denied) return 'denied';
}
for (const child of request.childRequests) {
if (child && child.approved) return 'approved';
}
for (const child of request.childRequests) {
if (child && child.requested) return 'pending';
}
}
return 'unknown'; return 'unknown';
} }
+67 -1
View File
@@ -80,7 +80,73 @@ function filterRequestsByUser(requests, username, showAll) {
}); });
} }
async function decorateRequestsWithArrLinks(requests, isAdmin) {
if (!isAdmin || !Array.isArray(requests)) return;
const arrRetrieverRegistry = require('./arrRetrievers');
await arrRetrieverRegistry.initialize();
const sonarrRetrievers = arrRetrieverRegistry.getRetrieversByType('sonarr') || [];
const radarrRetrievers = arrRetrieverRegistry.getRetrieversByType('radarr') || [];
const [sonarrData, radarrData] = await Promise.all([
Promise.all(sonarrRetrievers.map(async r => {
try {
const response = await require('axios').get(`${r.url}/api/v3/series`, {
headers: { 'X-Api-Key': r.apiKey }
});
return { instance: r, series: response.data || [] };
} catch {
return { instance: r, series: [] };
}
})),
Promise.all(radarrRetrievers.map(async r => {
try {
const response = await require('axios').get(`${r.url}/api/v3/movie`, {
headers: { 'X-Api-Key': r.apiKey }
});
return { instance: r, movies: response.data || [] };
} catch {
return { instance: r, movies: [] };
}
}))
]);
requests.forEach(req => {
// Determine if it's TV or Movie. Often `mediaType` is set, or `type === 'Tv'`
// Fallback to checking for TV specific IDs.
const isTv = req.mediaType === 'tv' || req.type === 'Tv' || req.tvDbId || req.tvdbId || req.theTvDbId || req.theTvdbId || req.TvDbId || req.TheTvDbId;
if (isTv) {
const tvdbId = req.theTvDbId || req.theTvdbId || req.tvDbId || req.tvdbId || req.TvDbId || req.TheTvDbId || req.theMovieDbId || req.theTmdbId;
if (!tvdbId) return;
for (const instData of sonarrData) {
const match = instData.series.find(s => s && (s.tvdbId === parseInt(tvdbId, 10) || s.tmdbId === parseInt(tvdbId, 10)));
if (match && match.titleSlug) {
req.arrLink = `${instData.instance.url}/series/${match.titleSlug}`;
req.arrType = 'sonarr';
break;
}
}
} else {
const tmdbId = req.theMovieDbId || req.imdbId || req.theTmdbId || req.TheMovieDbId || req.ImdbId;
if (!tmdbId) return;
for (const instData of radarrData) {
const match = instData.movies.find(m => m && (m.tmdbId === parseInt(tmdbId, 10) || m.imdbId === tmdbId));
if (match && match.titleSlug) {
req.arrLink = `${instData.instance.url}/movie/${match.titleSlug}`;
req.arrType = 'radarr';
break;
}
}
}
});
}
module.exports = { module.exports = {
extractRequestedUser, extractRequestedUser,
filterRequestsByUser filterRequestsByUser,
decorateRequestsWithArrLinks
}; };
+42
View File
@@ -233,6 +233,48 @@ describe('GET /api/ombi/requests', () => {
expect(res.body.requests.movie[0].requestedUser.userName).toBe('adminuser'); expect(res.body.requests.movie[0].requestedUser.userName).toBe('adminuser');
}); });
it('decorates TV requests with Sonarr links using tvDbId camelCase property (Issue #58)', async () => {
// 1. Setup mock instance config
process.env.SONARR_INSTANCES = JSON.stringify([
{ id: 'sonarr-1', name: 'Test Sonarr', url: 'https://sonarr.test', apiKey: 'sonarr-key' }
]);
// Reset and re-initialize retrievers registry to pick up the Sonarr instance
arrRetrieverRegistry.retrievers.clear();
arrRetrieverRegistry.initialized = false;
// 2. Setup mock Ombi TV request carrying `tvDbId` instead of `theTvDbId`
const tvRequestsWithTvDbId = [
{ id: 4, title: 'Superman Show', requestedUser: { userName: 'adminuser' }, requestedByAlias: 'adminuser', type: 'tv', tvDbId: '101' }
];
nock.cleanAll();
setupOmbiRequestMocks(OMBI_REQUESTS.movie, tvRequestsWithTvDbId);
// 3. Mock Sonarr API series call returning the series with matching tvdbId and titleSlug
nock('https://sonarr.test')
.get('/api/v3/series')
.reply(200, [
{ tvdbId: 101, title: 'Superman Show', titleSlug: 'superman-show' }
]);
const { cookies } = await authenticateUser(app, 'AdminUser', true);
const res = await request(app)
.get('/api/ombi/requests?showAll=true')
.set('Cookie', cookies)
.expect(200);
// 4. Assert decoration succeeded
const supermanShow = res.body.requests.tv.find(r => r.id === 4);
expect(supermanShow).toBeDefined();
expect(supermanShow.arrLink).toBe('https://sonarr.test/series/superman-show');
expect(supermanShow.arrType).toBe('sonarr');
// Clean up
delete process.env.SONARR_INSTANCES;
});
it('handles case-insensitive username matching', async () => { it('handles case-insensitive username matching', async () => {
const requestsWithMixedCase = [ const requestsWithMixedCase = [
{ id: 1, title: 'Test Movie', requestedUser: { userName: 'TestUser' }, requestedByAlias: 'TestUser', type: 'movie' }, { id: 1, title: 'Test Movie', requestedUser: { userName: 'TestUser' }, requestedByAlias: 'TestUser', type: 'movie' },
+149
View File
@@ -183,3 +183,152 @@ describe('arrRetrieverRegistry', () => {
}); });
}); });
}); });
describe('OmbiRetriever._hydrateRequest', () => {
let retriever;
beforeEach(() => {
retriever = new OmbiRetriever({
id: 'ombi-test',
name: 'Test Ombi',
url: 'http://localhost:5000',
apiKey: 'test-key'
});
// Seed the userMap cache
retriever.cache.userMap.set('user-1', {
id: 'user-1',
userName: 'testuser',
alias: 'TestUser',
userAlias: 'TestUser',
normalizedUserName: 'testuser'
});
retriever.cache.userMap.set('user-2', {
id: 'user-2',
userName: 'adminuser',
alias: 'AdminUser',
userAlias: 'AdminUser',
normalizedUserName: 'adminuser'
});
});
it('hydrates top-level requestedUserId', () => {
const req = {
id: 1,
requestedUserId: 'user-1',
requestedUser: {}
};
const result = retriever._hydrateRequest(req);
expect(result.requestedUser.userName).toBe('testuser');
expect(result.requestedUser.alias).toBe('TestUser');
});
it('hydrates childRequests requestedUserId (TV requests)', () => {
const req = {
id: 3,
title: 'Test Show',
requestedUserId: 'user-1',
requestedUser: {},
childRequests: [
{
id: 10,
requestedUserId: 'user-2',
requestedUser: {}
}
]
};
const result = retriever._hydrateRequest(req);
expect(result.requestedUser.userName).toBe('testuser');
expect(result.childRequests[0].requestedUser.userName).toBe('adminuser');
expect(result.childRequests[0].requestedUser.alias).toBe('AdminUser');
});
it('promotes requestedDate from childRequests to top level', () => {
const req = {
id: 3,
title: 'Test Show',
childRequests: [
{
id: 10,
requestedDate: '2026-05-15T10:00:00.000Z'
}
]
};
const result = retriever._hydrateRequest(req);
expect(result.requestedDate).toBe('2026-05-15T10:00:00.000Z');
expect(result.childRequests[0].requestedDate).toBe('2026-05-15T10:00:00.000Z');
});
it('does not overwrite existing top-level requestedDate', () => {
const req = {
id: 3,
requestedDate: '2026-01-01T00:00:00.000Z',
childRequests: [
{
id: 10,
requestedDate: '2026-05-15T10:00:00.000Z'
}
]
};
const result = retriever._hydrateRequest(req);
expect(result.requestedDate).toBe('2026-01-01T00:00:00.000Z');
});
it('handles PascalCase RequestedDate from childRequests', () => {
const req = {
id: 3,
childRequests: [
{
id: 10,
RequestedDate: '2026-06-01T12:00:00.000Z'
}
]
};
const result = retriever._hydrateRequest(req);
expect(result.requestedDate).toBe('2026-06-01T12:00:00.000Z');
});
it('returns unmodified request when no hydration needed', () => {
const req = {
id: 1,
title: 'Test Movie',
requestedUser: { userName: 'existing', alias: 'Existing' }
};
const result = retriever._hydrateRequest(req);
expect(result).toEqual(req);
});
it('handles null childRequests gracefully', () => {
const req = {
id: 3,
childRequests: null
};
const result = retriever._hydrateRequest(req);
expect(result).toEqual(req);
});
it('handles empty childRequests gracefully', () => {
const req = {
id: 3,
childRequests: []
};
const result = retriever._hydrateRequest(req);
expect(result).toEqual(req);
});
it('skips child hydration when child already has valid requestedUser', () => {
const req = {
id: 3,
childRequests: [
{
id: 10,
requestedUserId: 'user-1',
requestedUser: { userName: 'already_set', alias: 'AlreadySet' }
}
]
};
const result = retriever._hydrateRequest(req);
expect(result.childRequests[0].requestedUser.userName).toBe('already_set');
expect(result.childRequests[0].requestedUser.alias).toBe('AlreadySet');
});
});
+34
View File
@@ -58,6 +58,40 @@ describe('getRequestStatus', () => {
expect(getRequestStatus(makeRequest({ denied: true, approved: true }))).toBe('denied'); expect(getRequestStatus(makeRequest({ denied: true, approved: true }))).toBe('denied');
expect(getRequestStatus(makeRequest({ approved: true, requested: true }))).toBe('approved'); expect(getRequestStatus(makeRequest({ approved: true, requested: true }))).toBe('approved');
}); });
it('returns available from childRequests when top-level is absent (TV)', () => {
expect(getRequestStatus({ childRequests: [{ available: true }] })).toBe('available');
});
it('returns denied from childRequests when top-level is absent (TV)', () => {
expect(getRequestStatus({ childRequests: [{ denied: true }] })).toBe('denied');
});
it('returns approved from childRequests when top-level is absent (TV)', () => {
expect(getRequestStatus({ childRequests: [{ approved: true }] })).toBe('approved');
});
it('returns pending from childRequests when top-level is absent (TV)', () => {
expect(getRequestStatus({ childRequests: [{ requested: true }] })).toBe('pending');
});
it('follows priority inside childRequests: available > denied > approved > pending', () => {
expect(getRequestStatus({ childRequests: [
{ available: true, denied: true },
{ approved: true }
]})).toBe('available');
expect(getRequestStatus({ childRequests: [
{ denied: true, approved: true },
{ requested: true }
]})).toBe('denied');
expect(getRequestStatus({ childRequests: [
{ approved: true, requested: true }
]})).toBe('approved');
});
it('returns unknown for TV request with empty childRequests', () => {
expect(getRequestStatus({ childRequests: [] })).toBe('unknown');
});
}); });
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
+28
View File
@@ -130,6 +130,34 @@ describe('ombiHelpers', () => {
}; };
expect(extractRequestedUser(req)).toBe('child_user'); expect(extractRequestedUser(req)).toBe('child_user');
}); });
it('recursively extracts user from childRequests requestedUser object (hydrated TV)', () => {
const req = {
childRequests: [
{},
{ requestedUser: { userName: 'tv_user', alias: 'tv_alias' } }
]
};
expect(extractRequestedUser(req)).toBe('tv_alias');
});
it('recursively extracts user from childRequests requestedUser as string', () => {
const req = {
childRequests: [
{ requestedUser: 'string_user' }
]
};
expect(extractRequestedUser(req)).toBe('string_user');
});
it('extracts user from deeply nested childRequests with requestedByAlias fallback', () => {
const req = {
childRequests: [
{ requestedByAlias: 'deep_alias' }
]
};
expect(extractRequestedUser(req)).toBe('deep_alias');
});
}); });
describe('filterRequestsByUser', () => { describe('filterRequestsByUser', () => {