-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-pane-export.ts
More file actions
66 lines (63 loc) · 1.91 KB
/
Copy pathfile-pane-export.ts
File metadata and controls
66 lines (63 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { FileExportArchiveFormat } from "../components/settings/app-settings-types";
import {
copyLocalFile,
localExportPathsArchive,
sftpDownloadFile,
sftpExportPathsArchive,
} from "../tauri-api";
import type { RemoteSshSpec } from "../types";
import { fileExportArchiveFormatToApi } from "./app-preferences";
import { joinRemotePath } from "./file-pane-paths";
export function exportNeedsArchive(
names: string[],
entries: Array<{ name: string; isDir: boolean }>,
): boolean {
if (names.length !== 1) {
return true;
}
const row = entries.find((e) => e.name === names[0]);
return Boolean(row?.isDir);
}
export async function runRemoteFilePaneExport(args: {
spec: RemoteSshSpec;
parentPath: string;
names: string[];
entries: Array<{ name: string; isDir: boolean }>;
destPathKeyOrAbs: string;
archiveFormat: FileExportArchiveFormat;
}): Promise<string> {
const fmt = fileExportArchiveFormatToApi(args.archiveFormat);
if (exportNeedsArchive(args.names, args.entries)) {
return sftpExportPathsArchive(
args.spec,
args.parentPath,
args.names,
fmt,
args.destPathKeyOrAbs,
null,
);
}
const only = args.names[0]!;
const remotePath = joinRemotePath(args.parentPath, only);
return sftpDownloadFile(args.spec, remotePath, args.destPathKeyOrAbs);
}
export async function runLocalFilePaneExport(args: {
parentPathKey: string;
names: string[];
entries: Array<{ name: string; isDir: boolean }>;
destPathKeyOrAbs: string;
archiveFormat: FileExportArchiveFormat;
}): Promise<string> {
const fmt = fileExportArchiveFormatToApi(args.archiveFormat);
if (exportNeedsArchive(args.names, args.entries)) {
return localExportPathsArchive(
args.parentPathKey,
args.names,
fmt,
args.destPathKeyOrAbs,
null,
);
}
const only = args.names[0]!;
return copyLocalFile(args.parentPathKey, only, args.destPathKeyOrAbs, only);
}