CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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