better hardware polling on media page
Continuous Integration / backend-tests (push) Successful in 37s
Continuous Integration / frontend-check (push) Successful in 16s
Continuous Integration / e2e-tests (push) Successful in 6m9s

This commit is contained in:
2026-05-05 20:41:03 -04:00
parent fa171176fc
commit d398664e51
+33 -1
View File
@@ -243,6 +243,38 @@
} }
} }
async function pollHardware() {
try {
const res = await discoverHardware();
if (!res.data) return;
const prevPaths = new Set(discoveredAssets.map(a => a.device_path));
let hasNew = false;
discoveredAssets = (res.data as any[]).map(newAsset => {
if (!prevPaths.has(newAsset.device_path)) {
hasNew = true;
}
const oldAsset = discoveredAssets.find(a => a.device_path === newAsset.device_path);
if (oldAsset && oldAsset.hardware_info && newAsset.hardware_info) {
if (Object.keys(newAsset.hardware_info.tape || {}).length === 0 && Object.keys(oldAsset.hardware_info.tape || {}).length > 0) {
newAsset.hardware_info.tape = oldAsset.hardware_info.tape;
}
if (Object.keys(newAsset.hardware_info.drive || {}).length === 0 && Object.keys(oldAsset.hardware_info.drive || {}).length > 0) {
newAsset.hardware_info.drive = oldAsset.hardware_info.drive;
}
}
return newAsset;
});
if (hasNew) {
loadMedia(true, true);
}
} catch (error) {
console.error("Hardware discovery failed:", error);
}
}
let prevOnlineCount = $state(0); let prevOnlineCount = $state(0);
$effect(() => { $effect(() => {
@@ -275,7 +307,7 @@
console.error("Failed to load storage providers:", error); console.error("Failed to load storage providers:", error);
} }
pollInterval = setInterval(() => loadMedia(true), POLL_SLOW); pollInterval = setInterval(pollHardware, POLL_SLOW);
}); });
onDestroy(() => { onDestroy(() => {