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/create.ts
Views: 687
1
/*
2
API endpoint to create a new project.
3
4
This requires the user to be signed in so they are allowed to create a project.
5
*/
6
import getAccountId from "lib/account/get-account";
7
import create from "@cocalc/server/projects/create";
8
import getParams from "lib/api/get-params";
9
10
export default async function handle(req, res) {
11
const { title, description, image, license, public_path_id } = getParams(req);
12
const account_id = await getAccountId(req);
13
try {
14
const project_id = await createProject(
15
account_id,
16
title,
17
description,
18
image,
19
license,
20
public_path_id
21
);
22
res.json({ project_id });
23
} catch (err) {
24
res.json({ error: err.message });
25
}
26
}
27
28
async function createProject(
29
account_id,
30
title,
31
description,
32
image,
33
license,
34
public_path_id?: string
35
): Promise<string> {
36
if (!account_id) {
37
throw Error("user must be signed in");
38
}
39
return await create({
40
account_id,
41
title,
42
description,
43
image,
44
license,
45
public_path_id,
46
});
47
}
48
49