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)
|
||||
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"})
|
||||
|
|
|
|||
Reference in a new issue