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-serial-port-output.ts
Views: 687
/*1Get serial port output (since boot) for a compute server.23Any collaborator on the project containing the compute server has permission to get this serial output.4*/56import getAccountId from "lib/account/get-account";7import { getSerialPortOutput } from "@cocalc/server/compute/control";8import { getServerNoCheck } from "@cocalc/server/compute/get-servers";9import getParams from "lib/api/get-params";10import isCollaborator from "@cocalc/server/projects/is-collaborator";1112import { apiRoute, apiRouteOperation } from "lib/api";13import {14GetComputeServerSerialPortOutputInputSchema,15GetComputeServerSerialPortOutputOutputSchema,16} from "lib/api/schema/compute/get-serial-port-output";1718async function handle(req, res) {19try {20res.json(await get(req));21} catch (err) {22res.json({ error: `${err.message}` });23return;24}25}2627async function get(req) {28const account_id = await getAccountId(req);29if (!account_id) {30throw Error("user must be signed in");31}32// id of the server33const { id } = getParams(req);34const server = await getServerNoCheck(id);3536if (37!(await isCollaborator({38account_id,39project_id: server.project_id,40}))41) {42throw Error("must be a collaborator on project with compute server");43}4445return await getSerialPortOutput({46id,47account_id: server.account_id, // actual compute server owner48});49}5051export default apiRoute({52getSerialPortOutput: apiRouteOperation({53method: "POST",54openApiOperation: {55tags: ["Compute"],56},57})58.input({59contentType: "application/json",60body: GetComputeServerSerialPortOutputInputSchema,61})62.outputs([63{64status: 200,65contentType: "application/json",66body: GetComputeServerSerialPortOutputOutputSchema,67},68])69.handler(handle),70});717273