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/compute/cloud-filesystem/create.ts
Views: 688
1
/*
2
Create a cloud file system
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import { createCloudFilesystem, Options } from "@cocalc/server/compute/cloud-filesystem/create";
7
import { FIELDS } from "@cocalc/server/compute/cloud-filesystem/get";
8
import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";
9
10
import getParams from "lib/api/get-params";
11
12
export default async function handle(req, res) {
13
try {
14
res.json(await get(req));
15
} catch (err) {
16
res.json({ error: `${err.message}` });
17
return;
18
}
19
}
20
21
async function get(req) {
22
const account_id = await getAccountId(req);
23
if (!account_id) {
24
throw Error("must be signed in");
25
}
26
27
const params = getParams(req);
28
const opts: Partial<CloudFilesystem> = {};
29
for (const field of FIELDS) {
30
const x = params[field];
31
if (x !== undefined) {
32
opts[field] = x;
33
}
34
}
35
return await createCloudFilesystem({
36
...opts,
37
account_id,
38
} as Options);
39
}
40
41