跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

file-transfer.js

34 行 · 1.7 KB历史下载
1import { api, native, uploadFile } from "./api";
2
3export const shellFilePaths = (paths) => paths.map(path => `'${path.replaceAll("'", /^[A-Za-z]:\\/.test(path) ? "''" : "'\\''")}'`).join(" ") + " ";
4
5// Both native selection handles and browser File objects use the same guest
6// upload window. A failed batch is canceled before it can be delivered.
7export async function sendFiles(content, target, id, { valid = () => true, onProgress, windowTarget } = {}) {
8 const check = () => { if (!valid()) throw new Error("文件接收目标已切换,请返回原位置重试"); };
9 check();
10 const files = content.files || [];
11 if (!content.fileSelection && (!files.length || files.length > 100 || files.some(file => file.size > 2 * 1024 ** 3)))
12 throw new Error("每个文件不能超过 2 GB;一次最多 100 个文件。");
13 const request = await api("/input/files/start", { target, id, kind: content.kind || "paste", x: content.x, y: content.y, pid: windowTarget?.pid, window: windowTarget?.window });
14 const paths = [];
15 try {
16 check();
17 if (content.fileSelection) {
18 const result = await native("uploadHostFiles", { target, id: request.id, selection: content.fileSelection });
19 paths.push(...(result.paths || []));
20 } else {
21 for (const file of files) {
22 check();
23 const result = await uploadFile(`/input/files/${target}/${request.id}?${new URLSearchParams({ name: file.name })}`, file, { onProgress });
24 if (result.path) paths.push(result.path);
25 }
26 }
27 check();
28 await api("/input/files/finish", { target, id: request.id });
29 return { paths };
30 } catch (error) {
31 await api("/input/files/cancel", { target, id: request.id }).catch(() => {});
32 throw error;
33 }
34}