fix: resolve 404 file not found when permanently deleting files already in trash
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m20s

This commit is contained in:
Elijah 2026-05-23 14:38:09 -07:00
parent 1a1add48bf
commit 2596382ea8
2 changed files with 22 additions and 16 deletions

View file

@ -529,11 +529,6 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
resolvedPath := c.Locals("resolvedPath").(string)
relativePath := c.Locals("relativePath").(string)
// Check if file exists
if _, err := os.Stat(resolvedPath); os.IsNotExist(err) {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "file not found"})
}
// Soft-delete: move to .trash directory
trashPath := filepath.Join(h.Config.TrashDir, relativePath)
@ -557,6 +552,11 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"message": "permanently deleted"})
}
// For soft-delete, file must exist in regular storage
if _, err := os.Stat(resolvedPath); os.IsNotExist(err) {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "file not found"})
}
if err := os.MkdirAll(filepath.Dir(trashPath), 0755); err != nil {
fmt.Printf("MkdirAll error: %v\n", err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to prepare trash"})

View file

@ -632,6 +632,7 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
async function executeDeleteSelected() {
const count = selectedFiles.size;
const isPermanent = activeSection === 'trash';
try {
for (const path of selectedFiles) {
await api.deleteFile(path, isPermanent);
}
@ -641,8 +642,12 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
} else {
loadFiles(undefined, true);
}
setDeleteConfirm(null);
showToast(isPermanent ? `Permanently deleted ${count} item${count > 1 ? 's' : ''}` : `Deleted ${count} item${count > 1 ? 's' : ''}`);
} catch (err: any) {
showToast(`Delete failed: ${err.message}`);
} finally {
setDeleteConfirm(null);
}
}
async function executeDeleteSingle(file: FileItem) {
@ -654,10 +659,11 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
} else {
loadFiles(undefined, true);
}
setDeleteConfirm(null);
showToast(isPermanent ? `Permanently deleted ${file.name}` : `Deleted ${file.name}`);
} catch (err: any) {
showToast(`Delete failed: ${err.message}`);
} finally {
setDeleteConfirm(null);
}
}