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