Path: blob/master/src/packages/next/pages/api/v2/compute/get-server-state.ts
1451 views
/*1Checks with the cloud provider and gets the server state.2*/34import getAccountId from "lib/account/get-account";5import { state } from "@cocalc/server/compute/control";6import getParams from "lib/api/get-params";78import { apiRoute, apiRouteOperation } from "lib/api";9import {10GetComputeServerStateInputSchema,11GetComputeServerStateOutputSchema12} from "lib/api/schema/compute/get-server-state";131415async function handle(req, res) {16try {17res.json(await get(req));18} catch (err) {19res.json({ error: `${err.message}` });20return;21}22}2324async function get(req) {25const account_id = await getAccountId(req);26if (!account_id) {27throw Error("must be signed in");28}29const { id } = getParams(req);30return await state({31account_id,32id,33});34}3536export default apiRoute({37getServerState: apiRouteOperation({38method: "POST",39openApiOperation: {40tags: ["Compute"]41},42})43.input({44contentType: "application/json",45body: GetComputeServerStateInputSchema,46})47.outputs([48{49status: 200,50contentType: "application/json",51body: GetComputeServerStateOutputSchema,52},53])54.handler(handle),55});565758