feat(DeviceDetailOverlay, StatusPage): improve media file handling and streamline media set logic
This commit is contained in:
parent
6c2267c639
commit
0786fd087e
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user