feat(MediaManager): add folder configuration handling and update base URL display

This commit is contained in:
Jaime Idolpx 2026-06-08 12:49:52 -04:00
parent 841cf2f73d
commit 1f15e1fe20

View File

@ -509,6 +509,29 @@ export default function MediaManager({ initialPath = '/', rootPath, title, confi
useEffect(() => { localStorage.setItem('fileManager.sortKey', sortKey); }, [sortKey]); useEffect(() => { localStorage.setItem('fileManager.sortKey', sortKey); }, [sortKey]);
useEffect(() => { localStorage.setItem('fileManager.sortAsc', String(sortAsc)); }, [sortAsc]); useEffect(() => { localStorage.setItem('fileManager.sortAsc', String(sortAsc)); }, [sortAsc]);
// ── Folder config (.config) ──────────────────────────────────────────────
const [folderConfig, setFolderConfig] = useState<Record<string, string> | null>(null);
useEffect(() => {
let cancelled = false;
getFileContents(joinPath(path, '.config'))
.then(async blob => {
if (cancelled) return;
const cfg: Record<string, string> = {};
for (const line of (await blob.text()).split('\n')) {
const t = line.trim();
if (!t || t.startsWith('#')) continue;
const eq = t.indexOf('=');
if (eq < 0) continue;
cfg[t.slice(0, eq).trim()] = t.slice(eq + 1).trim();
}
setFolderConfig(cfg);
})
.catch(() => { if (!cancelled) setFolderConfig(null); });
return () => { cancelled = true; };
}, [path]);
const navigateTo = (p: string) => { const navigateTo = (p: string) => {
let norm = normalizePath(p); let norm = normalizePath(p);
if (rootPath && !norm.startsWith(rootPath)) norm = rootPath; if (rootPath && !norm.startsWith(rootPath)) norm = rootPath;
@ -717,6 +740,8 @@ export default function MediaManager({ initialPath = '/', rootPath, title, confi
} }
if (!dev.enabled) dev.enabled = 1; if (!dev.enabled) dev.enabled = 1;
if (folderConfig?.['cache'] === '.') dev.cache = splitPath(mountEntry.path).parent;
if (folderConfig?.['base_url']) dev.base_url = folderConfig['base_url'];
setConfig(newConfig); setConfig(newConfig);
setMountEntry(null); setMountEntry(null);
const deviceId = `${deviceType}-${key}`; const deviceId = `${deviceType}-${key}`;
@ -825,22 +850,6 @@ export default function MediaManager({ initialPath = '/', rootPath, title, confi
const pathParts = path.split('/').filter(Boolean); const pathParts = path.split('/').filter(Boolean);
const selCount = selected.size; const selCount = selected.size;
const deviceBaseUrl = useMemo(() => {
if (!config?.iec?.devices) return null;
const groups = ['drive', 'meatloaf', 'printer', 'network', 'other'];
for (const t of groups) {
for (const dev of Object.values(config.iec.devices[t] ?? {}) as any[]) {
if (dev?.base_url && (path.startsWith(dev.base_url) || dev.base_url === rootPath))
return dev.base_url as string;
}
}
for (const t of groups) {
for (const dev of Object.values(config.iec.devices[t] ?? {}) as any[]) {
if (dev?.base_url) return dev.base_url as string;
}
}
return null;
}, [config, path, rootPath]);
// ── Render ─────────────────────────────────────────────────────────────── // ── Render ───────────────────────────────────────────────────────────────
@ -916,8 +925,10 @@ export default function MediaManager({ initialPath = '/', rootPath, title, confi
); );
})} })}
</div> </div>
{deviceBaseUrl && ( {(folderConfig?.['base_url']) && (
<div className="text-xs text-neutral-400 mt-0.5 truncate">Base: {deviceBaseUrl}</div> <div className="text-xs text-neutral-400 mt-0.5 truncate">
Base: {folderConfig?.['base_url']}
</div>
)} )}
{showNewFile && ( {showNewFile && (