(function () {
window.FileCommands = window.FileCommands || [];
window.FileCommands.push({
id: "deletefile",
label: "🗑️ Move to Trash / Delete",
appliesTo: () => true, // applies to both files and folders
action: async ({ file, currentPath, showToast, confirmModal, reload }) => {
const fullPath = `${currentPath}/${file.name}`;
const isTrash = file.name === "_wastebasket";
console.log(`[deletefile.js] Deleting: ${fullPath}`);
const ok = await confirmModal({
title: isTrash ? "Permanently Delete Trash?" : "Move to Trash?",
body: isTrash
? "This will remove _wastebasket and all its contents. This cannot be undone."
: `Move ${file.name} to Trash?`,
confirmText: isTrash ? "Delete Trash" : "Move"
});
if (!ok) return;
try {
const res = await fetch("SFTPtrash.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ path: fullPath })
});
const data = await res.json();
if (data.success) {
showToast(isTrash ? "Trash deleted" : "Moved to Trash");
reload();
} else {
throw new Error(data.message || "Operation failed");
}
} catch (err) {
showToast("Error: " + err.message, "error");
}
}
});
console.log("[deletefile.js] Registered Delete command");
})();