From 0786fd087e8ddc832c4b2f30ed808967343817d3 Mon Sep 17 00:00:00 2001 From: Jaime Idolpx Date: Fri, 12 Jun 2026 00:37:24 -0400 Subject: [PATCH] feat(DeviceDetailOverlay, StatusPage): improve media file handling and streamline media set logic --- src/app/components/DeviceDetailOverlay.tsx | 4 ++-- src/app/components/StatusPage.tsx | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/app/components/DeviceDetailOverlay.tsx b/src/app/components/DeviceDetailOverlay.tsx index cb9aaeb..a4d37a7 100644 --- a/src/app/components/DeviceDetailOverlay.tsx +++ b/src/app/components/DeviceDetailOverlay.tsx @@ -3,7 +3,7 @@ import { SettingsInput } from './ui/settings-input'; import { X, ChevronLeft, ChevronRight, Printer, HardDrive, Network, Box, FolderOpen, MoreVertical, Play, Pause, SkipForward, SkipBack, RotateCcw } from 'lucide-react'; import { motion, AnimatePresence } from 'motion/react'; import { toast } from 'sonner'; -import { fileExists, getFileContents, joinPath } from '../webdav'; +import { fileExists, getFileContents, joinPath, stat } from '../webdav'; import MediaBrowser from './MediaBrowser'; import MediaSet, { mediaSetEntryUrl, type MediaSetEntry } from './MediaSet'; @@ -146,7 +146,7 @@ export default function DeviceDetailOverlay({ const candidates: string[] = []; for (let i = 1; i <= 10; i++) candidates.push(`${prefix}${i}${ext}`); let cancelled = false; - Promise.all(candidates.map(f => fileExists(f).catch(() => false))).then(flags => { + Promise.all(candidates.map(f => stat(f).then(r => r !== null).catch(() => false))).then(flags => { const found = candidates.filter((_, i) => flags[i]); if (!cancelled) setMediaSetFiles(found.length > 1 ? found : null); }); diff --git a/src/app/components/StatusPage.tsx b/src/app/components/StatusPage.tsx index 139d13f..eb54a41 100644 --- a/src/app/components/StatusPage.tsx +++ b/src/app/components/StatusPage.tsx @@ -45,15 +45,10 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta ? (activeDevice.base_url || splitPath(activeDevice.url || '/').parent) : null; - const mediaSetFiles: MediaSetEntry[] | null = (() => { - if (!activeDevice?.url) return null; - if (Array.isArray(activeDevice.media_set) && activeDevice.media_set.length > 0) - return activeDevice.media_set as MediaSetEntry[]; - const match = (activeDevice.url as string).match(/^(.+?)(\d+)(\.[^.]+)$/); - if (!match) return null; - const [, prefix, , ext] = match; - return Array.from({ length: 10 }, (_, i) => `${prefix}${i + 1}${ext}`); - })(); + const mediaSetFiles: MediaSetEntry[] | null = + Array.isArray(activeDevice?.media_set) && activeDevice.media_set.length > 1 + ? activeDevice.media_set as MediaSetEntry[] + : null; const switchActiveMedia = (file: string) => { const newConfig = JSON.parse(JSON.stringify(config));