Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/compute/get-servers-by-id.ts
1452 views
1
/*
2
Get multiple compute servers by their list of global ids.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import { getServersById } from "@cocalc/server/compute/get-servers";
7
import getParams from "lib/api/get-params";
8
import throttle from "@cocalc/util/api/throttle";
9
10
export default async function handle(req, res) {
11
try {
12
res.json(await get(req));
13
} catch (err) {
14
res.json({ error: `${err.message}` });
15
return;
16
}
17
}
18
19
async function get(req) {
20
const account_id = await getAccountId(req);
21
if (!account_id) {
22
throw Error("must be signed in");
23
}
24
throttle({
25
account_id,
26
endpoint: "compute/get-servers-by-id",
27
});
28
const { ids, fields } = getParams(req);
29
let servers = await getServersById({
30
account_id,
31
ids,
32
fields,
33
});
34
return servers;
35
}
36
37