// Copyright (C) 2026 Danilo M. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. .pragma library // What a staged file is, for its chip and the actions offered on it. The // text and image lists match desktop-assistant's, which decides what chat // accepts; this only decides what the card offers. // ponytail: the daemon also takes any text/* mime type; a file of such a // type with a suffix not listed here reads as "other" and is not offered // chat. Add the suffix when one shows up. const TEXT = [".py", ".c", ".h", ".cpp", ".hpp", ".rs", ".go", ".js", ".ts", ".jsx", ".tsx", ".sh", ".bash", ".zsh", ".lua", ".rb", ".pl", ".php", ".java", ".kt", ".swift", ".sql", ".toml", ".yaml", ".yml", ".json", ".ini", ".cfg", ".conf", ".md", ".rst", ".txt", ".csv", ".xml", ".html", ".css", ".diff", ".patch", ".slackbuild", ".info", ".desktop", ".service", ".qml"]; const IMAGE = [".png", ".jpg", ".jpeg", ".gif", ".webp"]; const VIDEO = [".mp4", ".mkv", ".webm", ".mov", ".avi", ".m4v"]; const ARCHIVE = [".zip", ".tar", ".gz", ".tgz", ".xz", ".txz", ".bz2", ".zst", ".7z", ".rar"]; // Kinds chat takes; the rest only get local actions. const CHAT = ["text", "image", "pdf"]; function name(path) { return path.slice(path.lastIndexOf("/") + 1); } function kind(path) { const n = name(path).toLowerCase(); const dot = n.lastIndexOf("."); const ext = dot > 0 ? n.slice(dot) : ""; if (ext === ".pdf") return "pdf"; if (IMAGE.includes(ext)) return "image"; if (VIDEO.includes(ext)) return "video"; if (ARCHIVE.includes(ext)) return "archive"; if (TEXT.includes(ext)) return "text"; return "other"; } function chats(k) { return CHAT.includes(k); } // A dropped URL to a local path, or "" for anything that is not a local // file: file:///path, or file://localhost/path; any other host is remote. function fromUrl(url) { const m = /^file:\/\/(localhost)?(\/.*)$/.exec(String(url)); if (!m) return ""; try { return decodeURIComponent(m[2]); } catch (e) { return ""; } } function file(path) { return { path: path, name: name(path), kind: kind(path) }; }