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/delete-server.ts
Views: 687
1
/*
2
Delete a compute server. This deprovisions the VM and sets the
3
deleted flag on the compute server entry in the database.
4
*/
5
6
import getAccountId from "lib/account/get-account";
7
import deleteServer from "@cocalc/server/compute/delete-server";
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
DeleteComputeServerInputSchema,
14
DeleteComputeServerOutputSchema,
15
} from "lib/api/schema/compute/delete-server";
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 } = getParams(req);
32
await deleteServer({
33
account_id,
34
id,
35
});
36
return OkStatus;
37
}
38
39
export default apiRoute({
40
deleteServer: apiRouteOperation({
41
method: "POST",
42
openApiOperation: {
43
tags: ["Compute"],
44
},
45
})
46
.input({
47
contentType: "application/json",
48
body: DeleteComputeServerInputSchema,
49
})
50
.outputs([
51
{
52
status: 200,
53
contentType: "application/json",
54
body: DeleteComputeServerOutputSchema,
55
},
56
])
57
.handler(handle),
58
});
59
60