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

This commit is contained in:
Elijah 2026-05-23 14:20:03 -07:00
parent db946461d7
commit 854da9a50d
2 changed files with 46 additions and 34 deletions

View file

@ -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"})

View file

@ -772,7 +772,7 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
}
function handleDragOver(e: React.DragEvent) {
if (draggedFile) return;
if (draggedFile || activeSection === 'trash') return;
if (!e.dataTransfer.types.includes('Files')) return;
e.preventDefault();
setDragOver(true);
@ -1754,31 +1754,33 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
</span>
</div>
<div className="flex items-center gap-2">
<button
className="p-2 hover:bg-white/5 rounded-lg transition-colors flex items-center gap-2 text-sm"
style={{ color: 'var(--color-text-primary)' }}
title="Download Selected"
onClick={() => {
if (!downloadToken) return;
const form = document.createElement('form');
form.method = 'POST';
form.action = api.getBulkDownloadUrl(downloadToken);
form.target = '_blank';
const input = document.createElement('input');
input.type = 'hidden';
input.name = 'paths';
input.value = JSON.stringify(Array.from(selectedFiles));
form.appendChild(input);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
setSelectedFiles(new Set());
}}
>
<Download className="w-4 h-4" />
</button>
{activeSection !== 'trash' && (
<button
className="p-2 hover:bg-white/5 rounded-lg transition-colors flex items-center gap-2 text-sm"
style={{ color: 'var(--color-text-primary)' }}
title="Download Selected"
onClick={() => {
if (!downloadToken) return;
const form = document.createElement('form');
form.method = 'POST';
form.action = api.getBulkDownloadUrl(downloadToken);
form.target = '_blank';
const input = document.createElement('input');
input.type = 'hidden';
input.name = 'paths';
input.value = JSON.stringify(Array.from(selectedFiles));
form.appendChild(input);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
setSelectedFiles(new Set());
}}
>
<Download className="w-4 h-4" />
</button>
)}
{activeSection !== 'trash' && (
<button
className="p-2 hover:bg-white/5 rounded-lg transition-colors flex items-center gap-2 text-sm"
@ -2094,11 +2096,13 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
style={{ backgroundColor: 'var(--color-bg-primary)', border: '1px solid var(--color-border)' }}
>
<div className="p-6">
<h2 className="text-xl font-bold mb-2" style={{ color: 'var(--color-text-primary)' }}>Move to Trash?</h2>
<h2 className="text-xl font-bold mb-2" style={{ color: 'var(--color-text-primary)' }}>
{activeSection === 'trash' ? 'Delete Permanently?' : 'Move to Trash?'}
</h2>
<p className="mb-6" style={{ color: 'var(--color-text-secondary)' }}>
{deleteConfirm.type === 'multiple'
? `Are you sure you want to move ${deleteConfirm.count} items to the trash?`
: `Are you sure you want to move ${deleteConfirm.file?.name} to the trash?`}
? (activeSection === 'trash' ? `Are you sure you want to permanently delete ${deleteConfirm.count} items?` : `Are you sure you want to move ${deleteConfirm.count} items to the trash?`)
: (activeSection === 'trash' ? `Are you sure you want to permanently delete ${deleteConfirm.file?.name}?` : `Are you sure you want to move ${deleteConfirm.file?.name} to the trash?`)}
</p>
<div className="flex justify-end gap-3">
<button
@ -2115,7 +2119,7 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
}}
className="px-4 py-2 rounded-lg text-sm font-medium transition-colors hover:opacity-90 bg-red-500 text-white"
>
Move to Trash
{activeSection === 'trash' ? 'Delete Permanently' : 'Move to Trash'}
</button>
</div>
</div>