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/write-text-file.ts
Views: 687
1
/* Write a text file to a project. */
2
3
import getAccountId from "lib/account/get-account";
4
import getParams from "lib/api/get-params";
5
import { isValidUUID } from "@cocalc/util/misc";
6
import callProject from "@cocalc/server/projects/call";
7
import { OkStatus } from "lib/api/status";
8
9
export default async function handle(req, res) {
10
const account_id = await getAccountId(req);
11
try {
12
if (account_id == null) throw Error("must be authenticated");
13
const { project_id, path, content } = getParams(req);
14
if (!isValidUUID(project_id))
15
throw Error("must set project_id to a valid uuid");
16
if (!path) throw Error("must specify a 'path'");
17
if (content == null) throw Error("must include content of file");
18
await callProject({
19
account_id,
20
project_id,
21
mesg: {
22
event: "write_text_file_to_project",
23
path,
24
content,
25
},
26
});
27
res.json(OkStatus);
28
} catch (err) {
29
res.json({ error: err.message });
30
}
31
}
32
33