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