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/start.ts
Views: 687
1
/*
2
API endpoint to start 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 { OkStatus } from "lib/api/status";
14
import {
15
StartProjectInputSchema,
16
StartProjectOutputSchema,
17
} from "lib/api/schema/projects/start";
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 start project");
32
}
33
const project = getProject(project_id);
34
await project.start();
35
res.json(OkStatus);
36
} catch (err) {
37
res.json({ error: err.message });
38
}
39
}
40
41
export default apiRoute({
42
startProject: apiRouteOperation({
43
method: "POST",
44
openApiOperation: {
45
tags: ["Projects"],
46
},
47
})
48
.input({
49
contentType: "application/json",
50
body: StartProjectInputSchema,
51
})
52
.outputs([
53
{
54
status: 200,
55
contentType: "application/json",
56
body: StartProjectOutputSchema,
57
},
58
])
59
.handler(handle),
60
});
61
62