add delete feature
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user