fix: resolve remaining trash UI issues and permanent delete backend logic
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
db946461d7
commit
854da9a50d
2 changed files with 46 additions and 34 deletions
|
|
@ -534,11 +534,21 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
|
|||
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)
|
||||
|
||||
// Check if permanent
|
||||
isPermanent := c.Query("permanent") == "true"
|
||||
if isPermanent {
|
||||
if err := os.RemoveAll(resolvedPath); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to permanently delete"})
|
||||
// Ensure we don't delete the root
|
||||
if resolvedPath == c.Locals("resolvedPath").(string) && relativePath == "." {
|
||||
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "cannot permanently delete root"})
|
||||
}
|
||||
|
||||
// Remove both potential locations to be safe
|
||||
os.RemoveAll(resolvedPath)
|
||||
if relativePath != "." {
|
||||
os.RemoveAll(trashPath)
|
||||
}
|
||||
|
||||
cleanPath := filepath.ToSlash(relativePath)
|
||||
|
|
@ -547,8 +557,6 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
|
|||
return c.JSON(fiber.Map{"message": "permanently deleted"})
|
||||
}
|
||||
|
||||
// Soft-delete: move to .trash directory
|
||||
trashPath := filepath.Join(h.Config.TrashDir, relativePath)
|
||||
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