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-template.ts
Views: 687
1
/*
2
Get A Single Template
3
*/
4
5
import { getTemplate } from "@cocalc/server/compute/templates";
6
import getParams from "lib/api/get-params";
7
8
import { apiRoute, apiRouteOperation } from "lib/api";
9
import {
10
GetComputeServerTemplateInputSchema,
11
GetComputeServerTemplateOutputSchema,
12
} from "lib/api/schema/compute/get-template";
13
14
15
async function handle(req, res) {
16
try {
17
res.json(await get(req));
18
} catch (err) {
19
res.json({ error: `${err.message}` });
20
return;
21
}
22
}
23
24
async function get(req) {
25
const { id } = getParams(req);
26
return await getTemplate(id);
27
}
28
29
export default apiRoute({
30
getTemplate: apiRouteOperation({
31
method: "POST",
32
openApiOperation: {
33
tags: ["Compute"]
34
},
35
})
36
.input({
37
contentType: "application/json",
38
body: GetComputeServerTemplateInputSchema,
39
})
40
.outputs([
41
{
42
status: 200,
43
contentType: "application/json",
44
body: GetComputeServerTemplateOutputSchema,
45
},
46
])
47
.handler(handle),
48
});
49
50