Path: blob/master/src/packages/project/conat/api/system.ts
5707 views
export async function ping() {1return { now: Date.now() };2}34export async function test({5project_id,6}: {7project_id?: string;8} = {}) {9return {10project_id: project_id ?? "",11server_time: Date.now(),12};13}1415export async function terminate() {}1617import { handleExecShellCode } from "@cocalc/project/exec_shell_code";18export { handleExecShellCode as exec };1920export { realpath } from "@cocalc/project/browser-websocket/realpath";2122import { version as versionNumber } from "@cocalc/util/smc-version";23export async function version() {24return versionNumber;25}2627import getListing from "@cocalc/backend/get-listing";28export async function listing({ path, hidden }) {29return await getListing(path, hidden);30}3132import { delete_files } from "@cocalc/backend/files/delete-files";3334export async function deleteFiles({ paths }: { paths: string[] }) {35return await delete_files(paths);36}3738import { getClient } from "@cocalc/project/client";39async function setDeleted(path) {40const client = getClient();41await client.set_deleted(path);42}4344import { move_files } from "@cocalc/backend/files/move-files";45export async function moveFiles({46paths,47dest,48}: {49paths: string[];50dest: string;51}) {52await move_files(paths, dest, setDeleted);53}5455import { rename_file } from "@cocalc/backend/files/rename-file";56export async function renameFile({ src, dest }: { src: string; dest: string }) {57await rename_file(src, dest, setDeleted);58}5960import { get_configuration } from "@cocalc/project/configuration";61export { get_configuration as configuration };6263import { canonical_paths } from "@cocalc/project/browser-websocket/canonical-path";64export { canonical_paths as canonicalPaths };6566import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";67import { readFile, writeFile } from "fs/promises";6869export async function writeTextFileToProject({70path,71content,72}: {73path: string;74content: string;75}): Promise<void> {76await ensureContainingDirectoryExists(path);77await writeFile(path, content);78}7980export async function readTextFileFromProject({81path,82}: {83path: string;84}): Promise<string> {85return (await readFile(path)).toString();86}8788export async function signal({89signal,90pids,91pid,92}: {93signal: number;94pids?: number[];95pid?: number;96}): Promise<void> {97const errors: Error[] = [];98const f = (pid) => {99try {100process.kill(pid, signal);101} catch (err) {102errors.push(err);103}104};105if (pid != null) {106f(pid);107}108if (pids != null) {109for (const pid of pids) {110f(pid);111}112}113if (errors.length > 0) {114throw errors[errors.length - 1];115}116}117118import jupyterExecute from "@cocalc/jupyter/stateless-api/execute";119export { jupyterExecute };120121import {122listRunningKernels,123stopKernel,124} from "@cocalc/jupyter/kernel/launch-kernel";125126export async function listJupyterKernels() {127return listRunningKernels();128}129130export async function stopJupyterKernel({ pid }: { pid: number }) {131const success = stopKernel(pid);132return { success };133}134135136