Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/compute/get-detailed-state.ts
Views: 687
/*1Get detailed state for a compute server.23This can get just the state for a given component.45One application of this is that the file system sync daemon6can check for the error message to be cleared.7*/89import getProjectOrAccountId from "lib/account/get-account";10import { getDetailedState } from "@cocalc/server/compute/set-detailed-state";11import getParams from "lib/api/get-params";12import isCollaborator from "@cocalc/server/projects/is-collaborator";1314import { apiRoute, apiRouteOperation } from "lib/api";15import {16GetDetailedServerStateInputSchema,17GetDetailedServerStateOutputSchema,18} from "lib/api/schema/compute/get-detailed-state";192021async function handle(req, res) {22try {23res.json(await get(req));24} catch (err) {25res.json({ error: `${err.message}` });26return;27}28}2930async function get(req) {31// This is a bit complicated because it can be used by a project api key,32// in which case project_id must not be passed in, or it can be auth'd33// by a normal api key or account, in which case project_id must be passed in.34const project_or_account_id = await getProjectOrAccountId(req);35if (!project_or_account_id) {36throw Error("invalid auth");37}38const { id, name, project_id: project_id0 } = getParams(req);3940let project_id;41if (!project_id0) {42project_id = project_or_account_id;43} else {44if (45!(await isCollaborator({46account_id: project_or_account_id,47project_id: project_id0,48}))49) {50throw Error("must be a collaborator on project with compute server");51}52project_id = project_id0;53}5455return await getDetailedState({56project_id,57id,58name,59});60}6162export default apiRoute({63getDetailedServerState: apiRouteOperation({64method: "POST",65openApiOperation: {66tags: ["Compute"]67},68})69.input({70contentType: "application/json",71body: GetDetailedServerStateInputSchema,72})73.outputs([74{75status: 200,76contentType: "text/plain",77body: GetDetailedServerStateOutputSchema,78},79])80.handler(handle),81});828384