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/projects/stop.ts
Views: 687
/*1API endpoint to stop a project running.23This requires the user to be signed in so they are allowed to use this project.4*/5import getAccountId from "lib/account/get-account";6import { getProject } from "@cocalc/server/projects/control";7import { isValidUUID } from "@cocalc/util/misc";8import isCollaborator from "@cocalc/server/projects/is-collaborator";9import getParams from "lib/api/get-params";1011import { apiRoute, apiRouteOperation } from "lib/api";12import {13StopProjectInputSchema,14StopProjectOutputSchema,15} from "lib/api/schema/projects/stop";16import { OkStatus } from "../../../../lib/api/status";1718async function handle(req, res) {19const { project_id } = getParams(req);20const account_id = await getAccountId(req);2122try {23if (!isValidUUID(project_id)) {24throw Error("project_id must be a valid uuid");25}26if (!account_id) {27throw Error("must be signed in");28}29if (!(await isCollaborator({ account_id, project_id }))) {30throw Error("must be a collaborator to stop project");31}32const project = getProject(project_id);33await project.stop();34res.json(OkStatus);35} catch (err) {36res.json({ error: err.message });37}38}3940export default apiRoute({41stopProject: apiRouteOperation({42method: "POST",43openApiOperation: {44tags: ["Projects"],45},46})47.input({48contentType: "application/json",49body: StopProjectInputSchema,50})51.outputs([52{53status: 200,54contentType: "application/json",55body: StopProjectOutputSchema,56},57])58.handler(handle),59});606162