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
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m20s
This commit is contained in:
parent
1a1add48bf
commit
2596382ea8
2 changed files with 22 additions and 16 deletions
|
|
@ -529,11 +529,6 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
|
||||||
resolvedPath := c.Locals("resolvedPath").(string)
|
resolvedPath := c.Locals("resolvedPath").(string)
|
||||||
relativePath := c.Locals("relativePath").(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
|
// Soft-delete: move to .trash directory
|
||||||
trashPath := filepath.Join(h.Config.TrashDir, relativePath)
|
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"})
|
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 {
|
if err := os.MkdirAll(filepath.Dir(trashPath), 0755); err != nil {
|
||||||
fmt.Printf("MkdirAll error: %v\n", err)
|
fmt.Printf("MkdirAll error: %v\n", err)
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to prepare trash"})
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to prepare trash"})
|
||||||
|
|
|
||||||
|
|
@ -632,17 +632,22 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
||||||
async function executeDeleteSelected() {
|
async function executeDeleteSelected() {
|
||||||
const count = selectedFiles.size;
|
const count = selectedFiles.size;
|
||||||
const isPermanent = activeSection === 'trash';
|
const isPermanent = activeSection === 'trash';
|
||||||
for (const path of selectedFiles) {
|
try {
|
||||||
await api.deleteFile(path, isPermanent);
|
for (const path of selectedFiles) {
|
||||||
|
await api.deleteFile(path, isPermanent);
|
||||||
|
}
|
||||||
|
setSelectedFiles(new Set());
|
||||||
|
if (activeSection === 'trash') {
|
||||||
|
loadTrash();
|
||||||
|
} else {
|
||||||
|
loadFiles(undefined, true);
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
setSelectedFiles(new Set());
|
|
||||||
if (activeSection === 'trash') {
|
|
||||||
loadTrash();
|
|
||||||
} else {
|
|
||||||
loadFiles(undefined, true);
|
|
||||||
}
|
|
||||||
setDeleteConfirm(null);
|
|
||||||
showToast(isPermanent ? `Permanently deleted ${count} item${count > 1 ? 's' : ''}` : `Deleted ${count} item${count > 1 ? 's' : ''}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeDeleteSingle(file: FileItem) {
|
async function executeDeleteSingle(file: FileItem) {
|
||||||
|
|
@ -654,10 +659,11 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
||||||
} else {
|
} else {
|
||||||
loadFiles(undefined, true);
|
loadFiles(undefined, true);
|
||||||
}
|
}
|
||||||
setDeleteConfirm(null);
|
|
||||||
showToast(isPermanent ? `Permanently deleted ${file.name}` : `Deleted ${file.name}`);
|
showToast(isPermanent ? `Permanently deleted ${file.name}` : `Deleted ${file.name}`);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showToast(`Delete failed: ${err.message}`);
|
showToast(`Delete failed: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
setDeleteConfirm(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue