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/touch.ts
Views: 687
1
/*
2
API endpoint to touch a project, thus updating the last_edited (and last_active
3
timestamps), and ensure the project is running.
4
5
This requires the user to be signed in so they are allowed to use this project.
6
*/
7
import getAccountId from "lib/account/get-account";
8
import { getProject } from "@cocalc/server/projects/control";
9
import { isValidUUID } from "@cocalc/util/misc";
10
import isCollaborator from "@cocalc/server/projects/is-collaborator";
11
import getParams from "lib/api/get-params";
12
13
export default async function handle(req, res) {
14
const account_id = await getAccountId(req);
15
const { project_id } = getParams(req);
16
17
try {
18
if (!isValidUUID(project_id)) {
19
throw Error("project_id must be a valid uuid");
20
}
21
if (!account_id) {
22
throw Error("must be signed in");
23
}
24
if (!(await isCollaborator({ account_id, project_id }))) {
25
throw Error("must be a collaborator to stop project");
26
}
27
const project = getProject(project_id);
28
await project.touch(account_id);
29
res.json({});
30
} catch (err) {
31
res.json({ error: err.message });
32
}
33
}
34
35