CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/browser-websocket/exec-code.ts
Views: 687
1
// Execute code on compute server in compute or filesystem container, or in this project.
2
3
import {
4
handleComputeServerFilesystemExec,
5
handleComputeServerComputeExec,
6
} from "@cocalc/sync-fs/lib/handle-api-call";
7
8
import { executeCode } from "@cocalc/backend/execute-code";
9
10
import type {
11
ExecuteCodeOptions,
12
ExecuteCodeOutput,
13
} from "@cocalc/util/types/execute-code";
14
15
interface Options extends ExecuteCodeOptions {
16
compute_server_id?: number;
17
filesystem?: boolean;
18
}
19
20
export default async function execCode(opts: Options): Promise<ExecuteCodeOutput> {
21
if (opts.compute_server_id) {
22
if (opts.filesystem) {
23
return await handleComputeServerFilesystemExec(opts);
24
} else {
25
return await handleComputeServerComputeExec(opts);
26
}
27
} else {
28
return await executeCode(opts);
29
}
30
}
31
32