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