feat(DeviceDetailOverlay, StatusPage): improve media file handling and streamline media set logic

This commit is contained in:
Jaime Idolpx 2026-06-12 00:37:24 -04:00
parent 6c2267c639
commit 0786fd087e
2 changed files with 6 additions and 11 deletions

View File

@ -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 { X, ChevronLeft, ChevronRight, Printer, HardDrive, Network, Box, FolderOpen, MoreVertical, Play, Pause, SkipForward, SkipBack, RotateCcw } from 'lucide-react';
import { motion, AnimatePresence } from 'motion/react'; import { motion, AnimatePresence } from 'motion/react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { fileExists, getFileContents, joinPath } from '../webdav'; import { fileExists, getFileContents, joinPath, stat } from '../webdav';
import MediaBrowser from './MediaBrowser'; import MediaBrowser from './MediaBrowser';
import MediaSet, { mediaSetEntryUrl, type MediaSetEntry } from './MediaSet'; import MediaSet, { mediaSetEntryUrl, type MediaSetEntry } from './MediaSet';
@ -146,7 +146,7 @@ export default function DeviceDetailOverlay({
const candidates: string[] = []; const candidates: string[] = [];
for (let i = 1; i <= 10; i++) candidates.push(`${prefix}${i}${ext}`); for (let i = 1; i <= 10; i++) candidates.push(`${prefix}${i}${ext}`);
let cancelled = false; 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]); const found = candidates.filter((_, i) => flags[i]);
if (!cancelled) setMediaSetFiles(found.length > 1 ? found : null); if (!cancelled) setMediaSetFiles(found.length > 1 ? found : null);
}); });

View File

@ -45,15 +45,10 @@ export default function StatusPage({ config, setConfig, onOpenFileManager }: Sta
? (activeDevice.base_url || splitPath(activeDevice.url || '/').parent) ? (activeDevice.base_url || splitPath(activeDevice.url || '/').parent)
: null; : null;
const mediaSetFiles: MediaSetEntry[] | null = (() => { const mediaSetFiles: MediaSetEntry[] | null =
if (!activeDevice?.url) return null; Array.isArray(activeDevice?.media_set) && activeDevice.media_set.length > 1
if (Array.isArray(activeDevice.media_set) && activeDevice.media_set.length > 0) ? activeDevice.media_set as MediaSetEntry[]
return activeDevice.media_set as MediaSetEntry[]; : null;
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 switchActiveMedia = (file: string) => { const switchActiveMedia = (file: string) => {
const newConfig = JSON.parse(JSON.stringify(config)); const newConfig = JSON.parse(JSON.stringify(config));