(function () {
window.FileCommands = window.FileCommands || [];
window.FileCommands.push({
id: "copyfile",
label: "📋 Copy to Clipboard",
appliesTo: (file) => !file.is_dir,
action: async ({ file, currentPath, showToast }) => {
const fullPath = `${currentPath}/${file.name}`;
console.log(`[copyfile.js] Copying ${fullPath}`);
try {
showToast("Reading file...");
const res = await fetch("SFTPdownload.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ path: fullPath })
});
if (!res.ok) {
const text = await res.text();
throw new Error(text || "Download failed");
}
const content = await res.text();
await navigator.clipboard.writeText(content);
showToast(`✅ Copied ${file.name} (${content.length} bytes)`);
} catch (err) {
showToast("Copy failed: " + err.message, "error");
}
}
});
console.log("[copyfile.js] Registered Copy command");
})();