Correctly update Dashboard UI for safety checks
This commit is contained in:
parent
ee7d07618d
commit
55fb0447eb
1 changed files with 178 additions and 49 deletions
|
|
@ -182,42 +182,123 @@
|
||||||
|
|
||||||
<!-- Recovery Modal -->
|
<!-- Recovery Modal -->
|
||||||
<div class="modal fade" id="recoveryModal" tabindex="-1">
|
<div class="modal fade" id="recoveryModal" tabindex="-1">
|
||||||
<div class="modal-dialog modal-lg">
|
<div class="modal-dialog modal-xl">
|
||||||
<div class="modal-content" style="background-color: var(--bg-card); border: 1px solid #444;">
|
<div class="modal-content" style="background-color: var(--bg-card); border: 1px solid #444;">
|
||||||
<div class="modal-header border-bottom border-secondary">
|
<div class="modal-header border-bottom border-secondary">
|
||||||
<h5 class="modal-title"><i class="bi bi-bandaid"></i> File Recovery</h5>
|
<h5 class="modal-title"><i class="bi bi-bandaid"></i> Advanced Recovery & Cleanup</h5>
|
||||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
This tool scans for video files in your source folder that are <strong>NOT</strong> in TA's
|
<i class="bi bi-info-circle"></i> This tool scans for files in your Source and Archive
|
||||||
database.
|
folders to find issues.
|
||||||
It will attempt to fetch metadata (using <code>yt-dlp</code>) and move them to the Import
|
|
||||||
folder.
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-grid mb-3">
|
<div class="d-grid mb-3">
|
||||||
<button class="btn btn-primary" onclick="scanRecoveryFiles()">
|
<button class="btn btn-primary" onclick="scanRecoveryFiles()">
|
||||||
<i class="bi bi-search"></i> Scan for Unindexed Files
|
<i class="bi bi-search"></i> Run System Scan
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs border-secondary mb-3" id="recoveryTabs" role="tablist">
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link active text-warning" data-bs-toggle="tab"
|
||||||
|
data-bs-target="#tab-unindexed">
|
||||||
|
<i class="bi bi-exclamation-triangle"></i> Unindexed (Import) <span
|
||||||
|
class="badge bg-secondary ms-1" id="badge-unindexed">0</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link text-danger" data-bs-toggle="tab" data-bs-target="#tab-rescue">
|
||||||
|
<i class="bi bi-life-preserver"></i> Rescue Needed <span
|
||||||
|
class="badge bg-secondary ms-1" id="badge-rescue">0</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="nav-link text-muted" data-bs-toggle="tab"
|
||||||
|
data-bs-target="#tab-redundant">
|
||||||
|
<i class="bi bi-trash"></i> Redundant Dupes <span class="badge bg-secondary ms-1"
|
||||||
|
id="badge-redundant">0</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<!-- Unindexed Files -->
|
||||||
|
<div class="tab-pane fade show active" id="tab-unindexed">
|
||||||
|
<p class="text-muted small">Files found on disk but missing from TubeArchivist. Recover
|
||||||
|
them to restore your library.</p>
|
||||||
<div class="table-responsive" style="max-height: 400px;">
|
<div class="table-responsive" style="max-height: 400px;">
|
||||||
<table class="table table-dark table-striped table-hover mb-0">
|
<table class="table table-dark table-striped table-hover mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Video ID</th>
|
<th>Video ID</th>
|
||||||
<th>Filename</th>
|
<th>Location</th>
|
||||||
<th>Size</th>
|
<th>Size</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="recovery-table-body">
|
<tbody id="tbody-unindexed">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="text-center text-muted">Click Scan to begin...</td>
|
<td colspan="4" class="text-center text-muted">Click Scan to begin...
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Rescue Files -->
|
||||||
|
<div class="tab-pane fade" id="tab-rescue">
|
||||||
|
<p class="text-danger small"><strong>CRITICAL:</strong> TubeArchivist thinks it has
|
||||||
|
these videos, but the source file is MISSING. However, we found a copy in your
|
||||||
|
archives! Recover immediately.</p>
|
||||||
|
<div class="table-responsive" style="max-height: 400px;">
|
||||||
|
<table class="table table-dark table-striped table-hover mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Video ID</th>
|
||||||
|
<th>Found At</th>
|
||||||
|
<th>Missing Source</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbody-rescue">
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="text-center text-muted">Click Scan to begin...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Redundant Files -->
|
||||||
|
<div class="tab-pane fade" id="tab-redundant">
|
||||||
|
<p class="text-muted small"><strong>SAFE TO DELETE:</strong> These files are duplicates.
|
||||||
|
TubeArchivist already has a verified copy in the source folder.</p>
|
||||||
|
<div class="table-responsive" style="max-height: 400px;">
|
||||||
|
<table class="table table-dark table-striped table-hover mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Video ID</th>
|
||||||
|
<th>Duplicate Path</th>
|
||||||
|
<th>Verified Source</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbody-redundant">
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="text-center text-muted">Click Scan to begin...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -342,41 +423,74 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function scanRecoveryFiles() {
|
async function scanRecoveryFiles() {
|
||||||
const tbody = document.getElementById('recovery-table-body');
|
// Loading state for all tabs
|
||||||
tbody.innerHTML = '<tr><td colspan="4" class="text-center"><div class="spinner-border text-primary" role="status"></div> Scanning...</td></tr>';
|
const loadingRow = '<tr><td colspan="4" class="text-center"><div class="spinner-border text-primary" role="status"></div> Scanning...</td></tr>';
|
||||||
|
const ids = ['tbody-unindexed', 'tbody-rescue', 'tbody-redundant'];
|
||||||
|
ids.forEach(id => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (el) el.innerHTML = loadingRow;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/recovery/scan', { method: 'POST' });
|
const res = await fetch('/api/recovery/scan', { method: 'POST' });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
tbody.innerHTML = '';
|
// Helper to render rows
|
||||||
if (data.count === 0) {
|
const renderRow = (f, type) => {
|
||||||
tbody.innerHTML = '<tr><td colspan="4" class="text-center text-success">No unindexed files found!</td></tr>';
|
const cleanPath = f.path.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
||||||
return;
|
if (type === 'unindexed') {
|
||||||
}
|
return `<tr>
|
||||||
|
|
||||||
data.files.forEach(f => {
|
|
||||||
const tr = document.createElement('tr');
|
|
||||||
tr.innerHTML = `
|
|
||||||
<td><code>${f.video_id}</code></td>
|
<td><code>${f.video_id}</code></td>
|
||||||
<td title="${f.path}" style="max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${f.filename}</td>
|
<td title="${f.path}"><small>${f.filename}</small></td>
|
||||||
<td>${f.size_mb} MB</td>
|
<td>${f.size_mb} MB</td>
|
||||||
<td>
|
<td><button class="btn btn-sm btn-success" onclick="startRecovery('${cleanPath}')"><i class="bi bi-cloud-arrow-up"></i> Recover</button></td>
|
||||||
<button class="btn btn-sm btn-success" onclick="startRecovery('${f.path.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}')">
|
</tr>`;
|
||||||
<i class="bi bi-cloud-arrow-up"></i> Recover
|
}
|
||||||
</button>
|
if (type === 'rescue') {
|
||||||
</td>
|
return `<tr>
|
||||||
`;
|
<td><code>${f.video_id}</code></td>
|
||||||
tbody.appendChild(tr);
|
<td title="${f.path}"><small>${f.filename}</small></td>
|
||||||
|
<td class="text-danger small">Missing from: ${f.ta_source}</td>
|
||||||
|
<td><button class="btn btn-sm btn-danger" onclick="startRecovery('${cleanPath}')"><i class="bi bi-life-preserver"></i> RESCUE</button></td>
|
||||||
|
</tr>`;
|
||||||
|
}
|
||||||
|
if (type === 'redundant') {
|
||||||
|
return `<tr>
|
||||||
|
<td><code>${f.video_id}</code></td>
|
||||||
|
<td title="${f.path}"><small>${f.filename}</small></td>
|
||||||
|
<td class="text-success small">Exists at: ${f.ta_source}</td>
|
||||||
|
<td><button class="btn btn-sm btn-outline-secondary" onclick="deleteFile('${cleanPath}')"><i class="bi bi-trash"></i> Delete</button></td>
|
||||||
|
</tr>`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear & Fill
|
||||||
|
ids.forEach(id => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (el) el.innerHTML = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update Badges
|
||||||
|
document.getElementById('badge-unindexed').innerText = data.files.unindexed.length;
|
||||||
|
document.getElementById('badge-rescue').innerText = data.files.rescue.length;
|
||||||
|
document.getElementById('badge-redundant').innerText = data.files.redundant.length;
|
||||||
|
|
||||||
|
// Populate Tables
|
||||||
|
data.files.unindexed.forEach(f => document.getElementById('tbody-unindexed').innerHTML += renderRow(f, 'unindexed'));
|
||||||
|
data.files.rescue.forEach(f => document.getElementById('tbody-rescue').innerHTML += renderRow(f, 'rescue'));
|
||||||
|
data.files.redundant.forEach(f => document.getElementById('tbody-redundant').innerHTML += renderRow(f, 'redundant'));
|
||||||
|
|
||||||
|
if (data.files.unindexed.length === 0) document.getElementById('tbody-unindexed').innerHTML = '<tr><td colspan="4" class="text-center text-muted">No unindexed files found.</td></tr>';
|
||||||
|
if (data.files.rescue.length === 0) document.getElementById('tbody-rescue').innerHTML = '<tr><td colspan="4" class="text-center text-muted">No rescue candidates found.</td></tr>';
|
||||||
|
if (data.files.redundant.length === 0) document.getElementById('tbody-redundant').innerHTML = '<tr><td colspan="4" class="text-center text-muted">No duplicates found.</td></tr>';
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tbody.innerHTML = `<tr><td colspan="4" class="text-center text-danger">Error: ${e}</td></tr>`;
|
alert("Scan failed: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startRecovery(filepath) {
|
async function startRecovery(filepath) {
|
||||||
if (!confirm("Start recovery for this file? This will try to fetch metadata and move it to the Import folder.")) return;
|
if (!confirm("Start recovery for this file? This will try to fetch metadata and move it to the Import folder.")) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/recovery/start', {
|
const res = await fetch('/api/recovery/start', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
@ -385,10 +499,25 @@
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
alert(data.message || "Recovery started! Check logs.");
|
alert(data.message || "Recovery started! Check logs.");
|
||||||
// Optionally remove the row
|
} catch (e) { alert("Error: " + e); }
|
||||||
} catch (e) {
|
|
||||||
alert("Error starting recovery: " + e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteFile(filepath) {
|
||||||
|
if (!confirm("⚠️ DELETE WARNING: Are you sure you want to delete this file?\n\n" + filepath + "\n\nOnly click OK if you are sure TA has a copy.")) return;
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/recovery/delete', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ filepath })
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.success) {
|
||||||
|
alert("File deleted.");
|
||||||
|
scanRecoveryFiles(); // Refresh
|
||||||
|
} else {
|
||||||
|
alert("Error: " + data.error);
|
||||||
|
}
|
||||||
|
} catch (e) { alert("Error: " + e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearLogs() {
|
function clearLogs() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue