Path: blob/master/src/packages/next/pages/api/v2/projects/touch.ts
1451 views
/*1API endpoint to touch a project, thus updating the last_edited (and last_active2timestamps), and ensure the project is running.34This requires the user to be signed in so they are allowed to use this project.5*/6import getAccountId from "lib/account/get-account";7import { getProject } from "@cocalc/server/projects/control";8import { isValidUUID } from "@cocalc/util/misc";9import isCollaborator from "@cocalc/server/projects/is-collaborator";10import getParams from "lib/api/get-params";1112export default async function handle(req, res) {13const account_id = await getAccountId(req);14const { project_id } = getParams(req);1516try {17if (!isValidUUID(project_id)) {18throw Error("project_id must be a valid uuid");19}20if (!account_id) {21throw Error("must be signed in");22}23if (!(await isCollaborator({ account_id, project_id }))) {24throw Error("must be a collaborator to stop project");25}26const project = getProject(project_id);27await project.touch(account_id);28res.json({});29} catch (err) {30res.json({ error: err.message });31}32}333435