From 5013d16b3571eb3ef86a3a3e3e2dc8e3a3659973 Mon Sep 17 00:00:00 2001 From: WonderAliceUwU Date: Mon, 3 Aug 2026 09:06:26 +0200 Subject: [PATCH] feature: improve performance and add remaining storage --- docker-compose.yml | 2 + server/index.ts | 34 +++++++++++- server/lib/services.ts | 35 +++++++++++++ shared/contracts.ts | 6 +++ src/App.tsx | 50 +++++++++++++++++- src/api.ts | 2 + src/index.css | 114 ++++++++++++++++++++++++++++++++++++++--- 7 files changed, 235 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index cbdddca..d39a915 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: environment: PORT: "8787" OMNIARR_DATA_DIR: /app/data + OMNIARR_STORAGE_PATH: /media TMDB_BEARER_TOKEN: "" volumes: - ./data:/app/data + - ./media:/media:ro diff --git a/server/index.ts b/server/index.ts index 9e7b4d0..7763872 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,5 +1,5 @@ import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'; -import { readFile } from 'node:fs/promises'; +import { readFile, statfs } from 'node:fs/promises'; import { resolve } from 'node:path'; import { defaultConfig, @@ -7,6 +7,7 @@ import { type AuthPayload, type EpisodeRequestPayload, type EpisodeWatchStateRequest, + type DiskSpaceStatus, type SeasonDeletePayload, type SeasonRequestPayload, type TitleDetailsRequest @@ -18,6 +19,7 @@ import { getConnectionStatuses, getDashboard, getHubPage, + getMediaDiskSpace, searchTitles, getTitleDetails, getTmdbLogos, @@ -47,6 +49,8 @@ const SESSION_COOKIE = 'omniarr_session'; const SESSION_TTL_MS = 1000 * 60 * 60 * 12; const sessions = new Map(); const failedAttempts = new Map(); +const DATA_DIR = resolve(process.env.OMNIARR_DATA_DIR || resolve(process.cwd(), 'data')); +const STORAGE_DIR = resolve(process.env.OMNIARR_STORAGE_PATH || DATA_DIR); const server = createServer(async (request, response) => { try { @@ -214,6 +218,12 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse): return; } + if (url.pathname === '/api/storage' && method === 'GET') { + const config = await readConfig(session!.encryptionKey); + sendJson(response, 200, await getDiskSpaceStatus(config)); + return; + } + if (url.pathname.startsWith('/api/hubs/') && method === 'GET') { const config = await readConfig(session!.encryptionKey); const page = decodeURIComponent(url.pathname.replace('/api/hubs/', '')); @@ -402,6 +412,28 @@ function createSession(encryptionKey: Buffer): string { return token; } +async function getDiskSpaceStatus(config: AppConfig): Promise { + if (process.env.OMNIARR_STORAGE_PATH) { + return getFilesystemDiskSpace(STORAGE_DIR); + } + + const mediaDiskSpace = await getMediaDiskSpace(config); + if (mediaDiskSpace) { + return mediaDiskSpace; + } + + return getFilesystemDiskSpace(DATA_DIR); +} + +async function getFilesystemDiskSpace(path: string): Promise { + const stats = await statfs(path); + return { + totalBytes: Number(stats.bsize) * Number(stats.blocks), + availableBytes: Number(stats.bsize) * Number(stats.bavail), + path + }; +} + function getSession(request: IncomingMessage): SessionRecord | null { const token = getSessionToken(request); if (!token) { diff --git a/server/lib/services.ts b/server/lib/services.ts index 53d1d96..cedd0b8 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -5,6 +5,7 @@ import type { CompletedDownloadItem, ConnectionStatus, DashboardResponse, + DiskSpaceStatus, DownloadItem, DownloadsResponse, EpisodeRequestPayload, @@ -440,6 +441,40 @@ export async function getServiceOptions(config: AppConfig): Promise { + const services = [ + { baseUrl: config.radarr.baseUrl, apiKey: config.radarr.apiKey, rootFolderPath: config.radarr.rootFolderPath }, + { baseUrl: config.sonarr.baseUrl, apiKey: config.sonarr.apiKey, rootFolderPath: config.sonarr.rootFolderPath } + ]; + + for (const service of services) { + if (!service.baseUrl || !service.apiKey) { + continue; + } + + try { + const folders = await fetchJson[]>(`${service.baseUrl}/api/v3/rootFolder`, { + headers: { 'X-Api-Key': service.apiKey } + }); + const folder = folders.find((entry) => String(entry.path || '') === service.rootFolderPath) || folders[0]; + const totalBytes = Number(folder?.totalSpace); + const availableBytes = Number(folder?.freeSpace); + + if (Number.isFinite(totalBytes) && totalBytes > 0 && Number.isFinite(availableBytes) && availableBytes >= 0) { + return { + totalBytes, + availableBytes, + path: String(folder?.path || service.rootFolderPath) + }; + } + } catch { + // The local data volume remains a useful fallback when an *arr service is unavailable. + } + } + + return null; +} + export async function loadJellyfinUsers(baseUrl: string, apiKey: string): Promise { if (!baseUrl.trim() || !apiKey.trim()) { return []; diff --git a/shared/contracts.ts b/shared/contracts.ts index 5c6ca1b..a697c94 100644 --- a/shared/contracts.ts +++ b/shared/contracts.ts @@ -85,6 +85,12 @@ export interface ConnectionStatus { message: string; } +export interface DiskSpaceStatus { + totalBytes: number; + availableBytes: number; + path?: string; +} + export interface MediaCard { id: string; tmdbId?: number; diff --git a/src/App.tsx b/src/App.tsx index 7438b8d..18e885f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,6 +19,7 @@ import { type ConnectionStatus, type CompletedDownloadItem, type DownloadItem, + type DiskSpaceStatus, type HubPageResponse, type MediaCard, type ProcessingItem, @@ -86,6 +87,7 @@ function App() { const [processingItems, setProcessingItems] = useState([]) const [completedDownloads, setCompletedDownloads] = useState([]) const [connections, setConnections] = useState([]) + const [diskSpace, setDiskSpace] = useState(null) const [hubPages, setHubPages] = useState>>({}) const [hubLoading, setHubLoading] = useState(false) @@ -120,10 +122,11 @@ function App() { } async function refreshBaseData() { - const [settings, serviceOptions, dashboard] = await Promise.all([ + const [settings, serviceOptions, dashboard, storage] = await Promise.all([ api.getSettings(), api.getOptions(), api.getDashboard(), + api.getDiskSpace(), ]) setConfig(settings) @@ -132,6 +135,7 @@ function App() { setProcessingItems(dashboard.processing || []) setCompletedDownloads(dashboard.completedDownloads || []) setConnections(dashboard.connections) + setDiskSpace(storage) setEntryStage(resolveEntryStage(settings, serviceOptions)) } @@ -477,6 +481,7 @@ function App() { busy={busy} connections={connections} currentUser={currentJellyfinUser} + diskSpace={diskSpace} onExitProfile={() => void transitionEntryStage('profiles')} route={route} setRoute={setRoute} @@ -556,6 +561,7 @@ function Sidebar(props: { route: AppRoute setRoute: (route: AppRoute) => void currentUser: string + diskSpace: DiskSpaceStatus | null connections: ConnectionStatus[] busy: boolean onExitProfile: () => void @@ -628,6 +634,7 @@ function Sidebar(props: {
+ {props.diskSpace ? : null}