Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync-fs/lib/conat/syncfs-client.ts
1503 views
1
/*
2
SyncFS Client Service, which runs on compute servers
3
*/
4
5
import { createSyncFsClientService } from "@cocalc/conat/service/syncfs-client";
6
import { type SyncFS } from "../index";
7
8
export async function initConatClientService({
9
syncfs,
10
compute_server_id,
11
project_id,
12
}: {
13
syncfs: SyncFS;
14
compute_server_id: number;
15
project_id: string;
16
}) {
17
// sanity check
18
if (!compute_server_id) {
19
throw Error("compute_server_id must be a positive integer");
20
}
21
const impl = {
22
sync: async () => {
23
await syncfs.sync();
24
},
25
26
copyFilesToHomeBase: async (opts: { paths: string[]; dest?: string }) => {
27
await syncfs.doApiRequest({
28
...opts,
29
event: "copy_from_compute_server_to_project",
30
});
31
},
32
33
copyFilesFromHomeBase: async (opts: { paths: string[]; dest?: string }) => {
34
await syncfs.doApiRequest({
35
...opts,
36
event: "copy_from_project_to_compute_server",
37
});
38
},
39
};
40
return await createSyncFsClientService({
41
compute_server_id,
42
project_id,
43
impl,
44
});
45
}
46
47