Path: blob/master/src/packages/project/conat/api/system.ts
1449 views
export async function ping() {1return { now: Date.now() };2}34export async function terminate() {}56import { handleExecShellCode } from "@cocalc/project/exec_shell_code";7export { handleExecShellCode as exec };89export { realpath } from "@cocalc/project/browser-websocket/realpath";1011import { version as versionNumber } from "@cocalc/util/smc-version";12export async function version() {13return versionNumber;14}1516import getListing from "@cocalc/backend/get-listing";17export async function listing({ path, hidden }) {18return await getListing(path, hidden);19}2021import { delete_files } from "@cocalc/backend/files/delete-files";2223export async function deleteFiles({ paths }: { paths: string[] }) {24return await delete_files(paths);25}2627import { getClient } from "@cocalc/project/client";28async function setDeleted(path) {29const client = getClient();30await client.set_deleted(path);31}3233import { move_files } from "@cocalc/backend/files/move-files";34export async function moveFiles({35paths,36dest,37}: {38paths: string[];39dest: string;40}) {41await move_files(paths, dest, setDeleted);42}4344import { rename_file } from "@cocalc/backend/files/rename-file";45export async function renameFile({ src, dest }: { src: string; dest: string }) {46await rename_file(src, dest, setDeleted);47}4849import { get_configuration } from "@cocalc/project/configuration";50export { get_configuration as configuration };5152import { canonical_paths } from "../../browser-websocket/canonical-path";53export { canonical_paths as canonicalPaths };5455import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";56import { readFile, writeFile } from "fs/promises";5758export async function writeTextFileToProject({59path,60content,61}: {62path: string;63content: string;64}): Promise<void> {65await ensureContainingDirectoryExists(path);66await writeFile(path, content);67}6869export async function readTextFileFromProject({70path,71}: {72path: string;73}): Promise<string> {74return (await readFile(path)).toString();75}7677export async function signal({78signal,79pids,80pid,81}: {82signal: number;83pids?: number[];84pid?: number;85}): Promise<void> {86const errors: Error[] = [];87const f = (pid) => {88try {89process.kill(pid, signal);90} catch (err) {91errors.push(err);92}93};94if (pid != null) {95f(pid);96}97if (pids != null) {98for (const pid of pids) {99f(pid);100}101}102if (errors.length > 0) {103throw errors[errors.length - 1];104}105}106107import jupyterExecute from "@cocalc/jupyter/stateless-api/execute";108export { jupyterExecute };109110111