add delete feature

This commit is contained in:
Rutra
2026-05-04 15:16:07 +02:00
parent ac81ac530f
commit 9c51891828
6 changed files with 37 additions and 4 deletions

View File

@@ -159,6 +159,11 @@
text-xs rounded-lg transition">
Open
</a>
<button onclick="deleteFile('{{ file.filename }}', this)"
class="px-3 py-1.5 bg-red-900/40 hover:bg-red-900/60 text-red-400
text-xs rounded-lg transition">
Delete
</button>
</div>
</div>
@@ -322,6 +327,22 @@
xhr.send(formData)
}
// ── Delete file ──────────────────────────────────────────────────
async function deleteFile(filename, btn) {
if (!confirm(`Delete "${filename}"?`)) return
btn.disabled = true
const res = await fetch(`/media/${encodeURIComponent(filename)}`, {
method: 'DELETE',
headers: { 'X-CSRF-TOKEN': CSRF_TOKEN },
})
if (res.ok) {
btn.closest('.bg-gray-900').remove()
} else {
alert('Could not delete the file.')
btn.disabled = false
}
}
// ── Copy URL to clipboard ─────────────────────────────────────────
function copyUrl(url) {
const fullUrl = window.location.origin + url