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/get-images.ts
Views: 687
1
/*
2
Get IMAGES.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import { getImages } from "@cocalc/server/compute/images";
7
import getParams from "lib/api/get-params";
8
import userIsInGroup from "@cocalc/server/accounts/is-in-group";
9
10
import { apiRoute, apiRouteOperation } from "lib/api";
11
import {
12
GetComputeServerImagesInputSchema,
13
GetComputeServerImagesOutputSchema,
14
} from "lib/api/schema/compute/get-images";
15
16
async function handle(req, res) {
17
try {
18
res.json(await get(req));
19
} catch (err) {
20
res.json({ error: `${err.message}` });
21
return;
22
}
23
}
24
25
async function get(req) {
26
const account_id = await getAccountId(req);
27
if (!account_id) {
28
throw Error("must be signed in");
29
}
30
let { noCache } = getParams(req);
31
if (noCache) {
32
// NOTE: only admins can specify noCache
33
if (!(await userIsInGroup(account_id, "admin"))) {
34
throw Error("only admin are allowed to specify noCache");
35
}
36
}
37
return await getImages({ noCache: !!noCache });
38
}
39
40
export default apiRoute({
41
getImages: apiRouteOperation({
42
method: "POST",
43
openApiOperation: {
44
tags: ["Compute"],
45
},
46
})
47
.input({
48
contentType: "application/json",
49
body: GetComputeServerImagesInputSchema,
50
})
51
.outputs([
52
{
53
status: 200,
54
contentType: "application/json",
55
body: GetComputeServerImagesOutputSchema,
56
},
57
])
58
.handler(handle),
59
});
60
61