mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 07:32:54 +00:00
* fix(sftp): paste folders as directories instead of empty files (#1266) Prefer Electron readClipboardFiles and extractDropEntries over clipboardData.files, upload pasted directories via uploadExternalFolderPath, and add macOS NSFilenames clipboard support. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(sftp): harden clipboard paste after review findings Start extractDropEntries synchronously during paste, restore path-backed file snapshot fallback, handle per-folder upload failures, and add public.file-url clipboard test. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b1f930a995
commit
f2c2501fa5
5 files changed
+170
-55
No files matched your search
@@ -127,6 +127,23 @@ function readClipboardFiles({
|
||||
) {
|
||||
return parseClipboardTextFilePaths(clipboard.readText(), options);
|
||||
}
|
||||
|
||||
if (typeof clipboard.read === "function") {
|
||||
for (const format of ["NSFilenamesPboardType", "public.file-url"]) {
|
||||
if (!formats.includes(format)) continue;
|
||||
const raw = clipboard.read(format);
|
||||
if (typeof raw !== "string" || raw.trim().length === 0) continue;
|
||||
if (raw.includes("file://")) {
|
||||
const files = parseClipboardTextFilePaths(raw, options);
|
||||
if (files.length > 0) return files;
|
||||
}
|
||||
const files = collectExistingFiles(
|
||||
raw.split(/\r?\n/).map((entry) => entry.trim()).filter(Boolean),
|
||||
options,
|
||||
);
|
||||
if (files.length > 0) return files;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -81,6 +81,46 @@ test("ignores plain text paths without file uri formats", () => {
|
||||
assert.deepEqual(parseClipboardTextFilePaths("/Users/me/a.txt", { fsImpl, pathImpl: require("node:path") }), []);
|
||||
});
|
||||
|
||||
test("reads macOS public.file-url clipboard paths", () => {
|
||||
const fsImpl = createFs({
|
||||
"/Users/me/folder": "directory",
|
||||
});
|
||||
const clipboard = {
|
||||
availableFormats: () => ["public.file-url"],
|
||||
read: (format) => {
|
||||
if (format === "public.file-url") {
|
||||
return "file:///Users/me/folder";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(readClipboardFiles({ clipboard, fsImpl, pathImpl: require("node:path") }), [
|
||||
{ path: "/Users/me/folder", name: "folder", isDirectory: true, size: 0 },
|
||||
]);
|
||||
});
|
||||
|
||||
test("reads macOS NSFilenamesPboardType clipboard paths", () => {
|
||||
const fsImpl = createFs({
|
||||
"/Users/me/folder": "directory",
|
||||
"/Users/me/a.txt": "file",
|
||||
});
|
||||
const clipboard = {
|
||||
availableFormats: () => ["NSFilenamesPboardType"],
|
||||
read: (format) => {
|
||||
if (format === "NSFilenamesPboardType") {
|
||||
return "/Users/me/folder\n/Users/me/a.txt";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(readClipboardFiles({ clipboard, fsImpl, pathImpl: require("node:path") }), [
|
||||
{ path: "/Users/me/folder", name: "folder", isDirectory: true, size: 0 },
|
||||
{ path: "/Users/me/a.txt", name: "a.txt", isDirectory: false, size: 42 },
|
||||
]);
|
||||
});
|
||||
|
||||
test("reads CF_HDROP before falling back to FileNameW", () => {
|
||||
const filesOffset = 20;
|
||||
const header = Buffer.alloc(filesOffset);
|
||||
|
||||
Reference in new issue
Block a user