feat: add filesystem permissions check and improved batch deletion error handling
All checks were successful
Docker Build / build (push) Successful in 15s

This commit is contained in:
wander 2026-03-08 05:10:37 -04:00
parent 62428c313b
commit 85f7a18883
2 changed files with 170 additions and 96 deletions

View file

@ -8,7 +8,7 @@
let results: any = { unindexed: [], rescue: [], redundant: [], lost: [] };
let pollInterval: ReturnType<typeof setInterval>;
// New State for Destruct Mode & Multi-selection
// State for Destruct Mode & Multi-selection
let destructMode = false;
let selectedPaths = new Set<string>();
@ -19,6 +19,22 @@
let loadingChannels = false;
let searchingVideos = false;
// Permissions state
let permissions: any = null;
let loadingPermissions = false;
async function checkPermissions() {
loadingPermissions = true;
try {
const res = await fetch("/api/system/check-permissions");
permissions = await res.json();
} catch (e) {
console.error("Failed to check permissions", e);
} finally {
loadingPermissions = false;
}
}
async function startScan() {
scanning = true;
try {
@ -111,7 +127,6 @@
}
if (!confirm(msg)) return;
if (destructMode && !confirm("FINAL WARNING: This is IRREVERSIBLE. Delete source file now?")) return;
try {
@ -128,7 +143,10 @@
alert("Deleted.");
if (activeTab === "channels") fetchChannelVideos(selectedChannel);
else startScan();
} else alert("Error deleting file.");
} else {
const err = d.errors?.[0] || "Unknown error";
alert(`Error deleting file: ${err}`);
}
} catch (e) {
alert(e);
}
@ -155,7 +173,14 @@
headers: { "Content-Type": "application/json" },
});
const d = await res.json();
alert(`Batch complete. Success: ${d.success_count}, Failed: ${d.fail_count}`);
if (d.fail_count > 0) {
const firstErr = d.errors?.[0] || "Check backend logs.";
alert(`Batch partially failed.\nSuccess: ${d.success_count}\nFailed: ${d.fail_count}\n\nFirst error: ${firstErr}`);
} else {
alert(`Batch complete. Deleted ${d.success_count} items.`);
}
selectedPaths = new Set();
if (activeTab === "channels") fetchChannelVideos(selectedChannel);
else startScan();
@ -170,7 +195,7 @@
} else {
selectedPaths.add(path);
}
selectedPaths = selectedPaths; // Trigger Svelte reactivity
selectedPaths = selectedPaths;
}
function toggleAll() {
@ -184,8 +209,12 @@
$: allSelected = (activeTab === "channels" ? channelVideos : results[activeTab])?.length > 0 && selectedPaths.size === (activeTab === "channels" ? channelVideos : results[activeTab])?.length;
$: sourceRO = permissions?.source?.writeable === false;
$: targetRO = permissions?.target?.writeable === false;
onMount(() => {
fetchChannels();
checkPermissions();
});
</script>
@ -193,11 +222,11 @@
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm p-4"
>
<div
class="bg-cyber-card border border-neon-cyan/30 rounded-xl w-full max-w-5xl h-[80vh] flex flex-col shadow-[0_0_50px_rgba(0,243,255,0.1)]"
class="bg-cyber-card border border-neon-cyan/30 rounded-xl w-full max-w-5xl h-[80vh] flex flex-col shadow-[0_0_50px_rgba(0,243,255,0.1)] overflow-hidden"
>
<!-- Header -->
<div
class="p-5 border-b border-gray-800 flex justify-between items-center"
class="p-5 border-b border-gray-800 flex justify-between items-center bg-gray-900/40"
>
<h2 class="text-xl font-bold text-white flex items-center gap-2">
<i class="bi bi-bandaid text-neon-pink"></i> Advanced Recovery
@ -207,16 +236,36 @@
</h2>
<button
on:click={() => dispatch("close")}
class="text-gray-500 hover:text-white"
class="text-gray-500 hover:text-white transition-colors"
aria-label="Close"><i class="bi bi-x-lg"></i></button
>
</div>
<!-- Permission Warnings -->
{#if sourceRO || targetRO}
<div class="bg-red-900/30 border-b border-red-500/50 p-3 flex items-center gap-3 animate-in fade-in slide-in-from-top duration-300">
<i class="bi bi-exclamation-octagon-fill text-red-500 text-lg"></i>
<div class="text-xs text-red-200">
<span class="font-bold uppercase">Filesystem Alert:</span>
{#if sourceRO && targetRO}
Both Source AND Target directories are currently <span class="text-white underline">READ-ONLY</span>. Deletion and reorganization will fail.
{:else if sourceRO}
Source archive is <span class="text-white underline">READ-ONLY</span>. Destruct Mode will fail.
{:else}
Target library is <span class="text-white underline">READ-ONLY</span>. Symlink cleanup will fail.
{/if}
</div>
<button on:click={checkPermissions} class="ml-auto text-[10px] bg-red-500/20 hover:bg-red-500/40 px-2 py-1 rounded border border-red-500/30 transition-colors">
Retry Check
</button>
</div>
{/if}
<!-- Controls -->
<div class="p-4 bg-gray-900/50 flex flex-wrap gap-4 justify-between items-center">
<div class="flex items-center gap-3">
<button
class="btn-primary px-6 py-2 rounded font-bold text-black bg-neon-cyan hover:bg-white transition-colors disabled:opacity-50"
class="btn-primary px-6 py-2 rounded font-bold text-black bg-neon-cyan hover:bg-white transition-all transform active:scale-95 disabled:opacity-50"
on:click={startScan}
disabled={scanning}
>
@ -225,8 +274,9 @@
{#if selectedPaths.size > 0}
<button
class="px-6 py-2 rounded font-bold text-white bg-red-600 hover:bg-red-500 transition-colors flex items-center gap-2"
class="px-6 py-2 rounded font-bold text-white bg-red-600 hover:bg-red-500 transition-all transform active:scale-95 flex items-center gap-2 shadow-[0_0_15px_rgba(220,38,38,0.4)]"
on:click={deleteSelected}
disabled={targetRO || (destructMode && sourceRO)}
>
<i class="bi bi-trash"></i> Delete Selected ({selectedPaths.size})
</button>
@ -238,29 +288,31 @@
<label class="relative inline-flex items-center cursor-pointer group">
<input type="checkbox" bind:checked={destructMode} class="sr-only peer">
<div class="w-11 h-6 bg-gray-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-red-600"></div>
<span class="ml-3 text-sm font-medium text-gray-300 group-hover:text-white transition-colors">
<span class="ml-3 text-sm font-medium text-gray-300 group-hover:text-white transition-colors flex items-center gap-2">
Destruct Mode
<i class="bi bi-exclamation-triangle-fill text-red-500 ml-1 {destructMode ? 'visible' : 'opacity-0'}"></i>
{#if destructMode}
<i class="bi bi-exclamation-triangle-fill text-red-500 animate-pulse"></i>
{/if}
</span>
</label>
<div class="text-xs text-mono text-gray-500">Status: <span class="text-neon-cyan">{status}</span></div>
<div class="text-xs text-mono text-gray-500">Status: <span class="text-neon-cyan underline decoration-dotted">{status}</span></div>
</div>
</div>
<!-- Tabs -->
<div class="flex border-b border-gray-800 px-4">
<div class="flex border-b border-gray-800 px-4 bg-gray-900/20">
{#each ["unindexed", "rescue", "redundant", "lost", "channels"] as tab}
<button
class="px-4 py-3 text-sm font-semibold capitalize border-b-2 transition-colors flex items-center gap-2
class="px-4 py-3 text-sm font-semibold capitalize border-b-2 transition-all flex items-center gap-2
{activeTab === tab
? 'border-neon-cyan text-neon-cyan'
: 'border-transparent text-gray-500 hover:text-gray-300'}"
? 'border-neon-cyan text-neon-cyan bg-neon-cyan/5'
: 'border-transparent text-gray-500 hover:text-gray-300 hover:bg-white/5'}"
on:click={() => { activeTab = tab as any; selectedPaths = new Set(); }}
>
{tab}
{#if tab !== 'channels'}
<span class="bg-gray-800 text-xs px-1.5 rounded-full"
<span class="bg-gray-800 text-[10px] px-1.5 py-0.5 rounded-full min-w-[1.2rem] text-center"
>{results[tab]?.length || 0}</span
>
{/if}
@ -275,9 +327,9 @@
<!-- Channel Selector -->
<div class="flex gap-4 items-end">
<div class="flex-grow">
<label class="block text-xs text-gray-500 mb-1">Select Channel</label>
<label class="block text-[10px] text-gray-500 mb-1 uppercase tracking-widest">Select Channel (Indexed Only)</label>
<select
class="w-full bg-gray-900 border border-gray-700 rounded p-2 text-white outline-none focus:border-neon-cyan"
class="w-full bg-gray-900 border border-gray-700 rounded p-2 text-white outline-none focus:border-neon-cyan transition-colors"
value={selectedChannel}
on:change={(e) => fetchChannelVideos(e.currentTarget.value)}
>
@ -288,22 +340,24 @@
</select>
</div>
<button
class="btn-secondary px-4 py-2 rounded bg-gray-800 text-white hover:bg-gray-700"
class="p-2.5 rounded bg-gray-800 text-white hover:bg-gray-700 transition-colors border border-gray-700"
on:click={fetchChannels}
title="Refresh Channel List"
>
<i class="bi bi-arrow-clockwise"></i>
</button>
</div>
<!-- Video Table -->
<div class="flex-grow overflow-y-auto border border-gray-800 rounded">
<div class="flex-grow overflow-y-auto border border-gray-800 rounded bg-gray-900/20">
{#if searchingVideos}
<div class="flex items-center justify-center h-full text-neon-cyan animate-pulse">
Fetching videos...
<div class="flex flex-col items-center justify-center h-full text-neon-cyan gap-4">
<div class="w-8 h-8 border-2 border-neon-cyan border-t-transparent rounded-full animate-spin"></div>
<span class="text-xs font-mono animate-pulse">QUERYING TA DATABASE...</span>
</div>
{:else if channelVideos.length > 0}
<table class="w-full text-left text-xs text-gray-300 font-mono border-collapse">
<thead class="sticky top-0 bg-cyber-card z-10 shadow-sm">
<table class="w-full text-left text-[11px] text-gray-300 font-mono border-collapse">
<thead class="sticky top-0 bg-gray-900 z-10">
<tr class="text-gray-500 border-b border-gray-800">
<th class="p-3 w-10">
<input
@ -333,10 +387,11 @@
<td class="p-3 truncate max-w-[400px]" title={item.title}>{item.title}</td>
<td class="p-3 text-right">
<button
class="text-red-500 hover:underline flex items-center gap-1 ml-auto"
class="text-red-500 hover:text-red-400 font-bold transition-colors disabled:opacity-30"
on:click={() => deleteFile(item.path)}
disabled={targetRO || (destructMode && sourceRO)}
>
<i class="bi bi-trash"></i> Delete
<i class="bi bi-trash"></i>
</button>
</td>
</tr>
@ -344,9 +399,9 @@
</tbody>
</table>
{:else}
<div class="flex flex-col items-center justify-center h-full text-gray-600 gap-2">
<i class="bi bi-search text-3xl opacity-20"></i>
Select a channel to view its videos.
<div class="flex flex-col items-center justify-center h-full text-gray-700 gap-3">
<i class="bi bi-broadcast text-4xl opacity-10"></i>
<span class="text-xs uppercase tracking-widest font-bold">No channel selected</span>
</div>
{/if}
</div>
@ -356,11 +411,11 @@
class="flex flex-col items-center justify-center h-full text-neon-cyan gap-4"
>
<div class="w-12 h-12 border-4 border-neon-cyan border-t-transparent rounded-full animate-spin"></div>
<div class="animate-pulse font-mono">SYSTEM WIDE SCAN IN PROGRESS...</div>
<div class="animate-pulse font-mono tracking-widest">SYSTEM WIDE SCAN IN PROGRESS...</div>
</div>
{:else}
<table class="w-full text-left text-xs text-gray-300 font-mono border-collapse">
<thead class="sticky top-0 bg-cyber-card z-10 shadow-sm">
<table class="w-full text-left text-[11px] text-gray-300 font-mono border-collapse">
<thead class="sticky top-0 bg-gray-900 z-10">
<tr class="text-gray-500 border-b border-gray-800">
<th class="p-3 w-10">
<input
@ -370,9 +425,9 @@
class="accent-neon-cyan"
>
</th>
<th class="p-3">Video ID</th>
<th class="p-3">Filename / Path</th>
<th class="p-3">Size/Info</th>
<th class="p-3">ID</th>
<th class="p-3">Filename / Target Path</th>
<th class="p-3">Info</th>
<th class="p-3 text-right">Action</th>
</tr>
</thead>
@ -408,33 +463,35 @@
<div class="flex justify-end gap-3">
{#if activeTab === "unindexed"}
<button
class="text-neon-green hover:underline flex items-center gap-1"
class="text-neon-green hover:underline flex items-center gap-1 transition-all hover:scale-105"
on:click={() =>
recoverFile(item.path)}
><i class="bi bi-plus-circle"></i> Recover</button
><i class="bi bi-plus-circle"></i> RECOVER</button
>
{:else if activeTab === "redundant"}
<button
class="text-red-500 hover:underline flex items-center gap-1"
class="text-red-500 hover:underline font-bold transition-all hover:scale-105 disabled:opacity-30"
on:click={() =>
deleteFile(item.path)}
><i class="bi bi-trash"></i> Delete</button
disabled={targetRO || (destructMode && sourceRO)}
><i class="bi bi-trash"></i> DELETE</button
>
{:else if activeTab === "lost"}
<button
class="text-neon-yellow hover:underline flex items-center gap-1"
><i class="bi bi-lightning-fill"></i> Force</button
><i class="bi bi-lightning-fill"></i> FORCE</button
>
<button
class="text-red-500 hover:underline flex items-center gap-1"
class="text-red-500 hover:underline font-bold disabled:opacity-30"
on:click={() =>
deleteFile(item.path)}
><i class="bi bi-trash"></i> Delete</button
disabled={targetRO || (destructMode && sourceRO)}
><i class="bi bi-trash"></i> DELETE</button
>
{:else}
<button
class="text-neon-pink hover:underline flex items-center gap-1"
><i class="bi bi-rescue-ambulance"></i> Rescue</button
><i class="bi bi-rescue-ambulance"></i> RESCUE</button
>
{/if}
</div>
@ -445,10 +502,10 @@
<tr
><td
colspan="5"
class="p-20 text-center text-gray-600 bg-gray-900/20"
class="p-20 text-center text-gray-600 bg-gray-900/10"
>
<i class="bi bi-cloud-check text-4xl mb-4 block opacity-20"></i>
Nothing detected in this category.
<i class="bi bi-shield-lock text-4xl mb-4 block opacity-10"></i>
NO ANOMALIES DETECTED IN THIS SECTOR.
</td
></tr
>
@ -464,4 +521,23 @@
.accent-neon-cyan {
accent-color: #00f3ff;
}
.bg-cyber-card {
background: linear-gradient(135deg, #0f0f13 0%, #050505 100%);
}
/* Custom Scrollbar for better Cyberpunk feel */
::-webkit-scrollbar {
width: 4px;
}
::-webkit-scrollbar-track {
background: rgba(15, 15, 15, 0.5);
}
::-webkit-scrollbar-thumb {
background: #00f3ff22;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #00f3ff66;
}
</style>