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-server-title.ts
Views: 687
1
/*
2
Get server title and color for a particular compute server.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import { getTitle } from "@cocalc/server/compute/get-servers";
7
import getParams from "lib/api/get-params";
8
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import {
11
GetComputeServerTitleInputSchema,
12
GetComputeServerTitleOutputSchema,
13
} from "lib/api/schema/compute/get-server-title";
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 account_id = await getAccountId(req);
26
if (!account_id) {
27
throw Error("must be signed in");
28
}
29
const { id } = getParams(req);
30
return await getTitle({ id, account_id });
31
}
32
33
export default apiRoute({
34
getServerTitle: apiRouteOperation({
35
method: "POST",
36
openApiOperation: {
37
tags: ["Compute"],
38
},
39
})
40
.input({
41
contentType: "application/json",
42
body: GetComputeServerTitleInputSchema,
43
})
44
.outputs([
45
{
46
status: 200,
47
contentType: "application/json",
48
body: GetComputeServerTitleOutputSchema,
49
},
50
])
51
.handler(handle),
52
});
53
54