Add DELETE /api/admin/backup/{filename} and delete button in Settings
This commit is contained in:
@@ -1929,6 +1929,19 @@ async def restore_backup(
|
|||||||
return {"restored": filename, "auto_backup": auto_dst.name if src.exists() else None}
|
return {"restored": filename, "auto_backup": auto_dst.name if src.exists() else None}
|
||||||
|
|
||||||
|
|
||||||
|
@app.delete("/api/admin/backup/{filename}")
|
||||||
|
async def delete_backup(
|
||||||
|
filename: str,
|
||||||
|
current_user: User = Depends(get_current_admin),
|
||||||
|
):
|
||||||
|
"""Delete a backup file."""
|
||||||
|
fp = BACKUP_DIR / filename
|
||||||
|
if not fp.exists() or ".." in filename:
|
||||||
|
raise HTTPException(status_code=404, detail="Backup not found")
|
||||||
|
fp.unlink()
|
||||||
|
return {"deleted": filename}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/admin/reset/{section}")
|
@app.post("/api/admin/reset/{section}")
|
||||||
async def reset_section(
|
async def reset_section(
|
||||||
section: str,
|
section: str,
|
||||||
|
|||||||
@@ -218,6 +218,22 @@ export default function Settings() {
|
|||||||
>
|
>
|
||||||
<Upload className="w-3.5 h-3.5" /> 還原
|
<Upload className="w-3.5 h-3.5" /> 還原
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
if (!confirm(`確定要刪除 ${b.filename}?`)) return
|
||||||
|
try {
|
||||||
|
await api.delete(`/api/admin/backup/${b.filename}`)
|
||||||
|
toast.success(`已刪除 ${b.filename}`)
|
||||||
|
fetchBackups()
|
||||||
|
} catch (e) {
|
||||||
|
toast.error("刪除失敗: " + (e.response?.data?.detail || e.message))
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="flex items-center gap-1 px-3 py-1.5 text-xs font-medium text-red-500 hover:text-red-700 hover:bg-red-50 rounded-md transition-colors"
|
||||||
|
title="Delete backup"
|
||||||
|
>
|
||||||
|
<Trash2 className="w-3.5 h-3.5" /> 刪除
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user