Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/conat/api/system.ts
1449 views
1
export async function ping() {
2
return { now: Date.now() };
3
}
4
5
export async function terminate() {}
6
7
import { handleExecShellCode } from "@cocalc/project/exec_shell_code";
8
export { handleExecShellCode as exec };
9
10
export { realpath } from "@cocalc/project/browser-websocket/realpath";
11
12
import { version as versionNumber } from "@cocalc/util/smc-version";
13
export async function version() {
14
return versionNumber;
15
}
16
17
import getListing from "@cocalc/backend/get-listing";
18
export async function listing({ path, hidden }) {
19
return await getListing(path, hidden);
20
}
21
22
import { delete_files } from "@cocalc/backend/files/delete-files";
23
24
export async function deleteFiles({ paths }: { paths: string[] }) {
25
return await delete_files(paths);
26
}
27
28
import { getClient } from "@cocalc/project/client";
29
async function setDeleted(path) {
30
const client = getClient();
31
await client.set_deleted(path);
32
}
33
34
import { move_files } from "@cocalc/backend/files/move-files";
35
export async function moveFiles({
36
paths,
37
dest,
38
}: {
39
paths: string[];
40
dest: string;
41
}) {
42
await move_files(paths, dest, setDeleted);
43
}
44
45
import { rename_file } from "@cocalc/backend/files/rename-file";
46
export async function renameFile({ src, dest }: { src: string; dest: string }) {
47
await rename_file(src, dest, setDeleted);
48
}
49
50
import { get_configuration } from "@cocalc/project/configuration";
51
export { get_configuration as configuration };
52
53
import { canonical_paths } from "../../browser-websocket/canonical-path";
54
export { canonical_paths as canonicalPaths };
55
56
import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";
57
import { readFile, writeFile } from "fs/promises";
58
59
export async function writeTextFileToProject({
60
path,
61
content,
62
}: {
63
path: string;
64
content: string;
65
}): Promise<void> {
66
await ensureContainingDirectoryExists(path);
67
await writeFile(path, content);
68
}
69
70
export async function readTextFileFromProject({
71
path,
72
}: {
73
path: string;
74
}): Promise<string> {
75
return (await readFile(path)).toString();
76
}
77
78
export async function signal({
79
signal,
80
pids,
81
pid,
82
}: {
83
signal: number;
84
pids?: number[];
85
pid?: number;
86
}): Promise<void> {
87
const errors: Error[] = [];
88
const f = (pid) => {
89
try {
90
process.kill(pid, signal);
91
} catch (err) {
92
errors.push(err);
93
}
94
};
95
if (pid != null) {
96
f(pid);
97
}
98
if (pids != null) {
99
for (const pid of pids) {
100
f(pid);
101
}
102
}
103
if (errors.length > 0) {
104
throw errors[errors.length - 1];
105
}
106
}
107
108
import jupyterExecute from "@cocalc/jupyter/stateless-api/execute";
109
export { jupyterExecute };
110
111