Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/licenses/get-license.ts
1452 views
1
/* Return information about a given license. */
2
3
import getLicense, {
4
getLicenseBySubscriptionId,
5
} from "@cocalc/server/licenses/get-license";
6
import getAccountId from "lib/account/get-account";
7
import getParams from "lib/api/get-params";
8
9
export default async function handle(req, res) {
10
try {
11
res.json(await get(req));
12
} catch (err) {
13
res.json({ error: err.message });
14
return;
15
}
16
}
17
18
async function get(req) {
19
const account_id = await getAccountId(req);
20
const { license_id, subscription_id } = getParams(req);
21
if (license_id) {
22
// account_id = null is OK -- then get very minimal info about the license.
23
return await getLicense(license_id, account_id);
24
} else if (subscription_id) {
25
// user must be owner of subscription
26
if (account_id == null) {
27
throw Error("must be signed in");
28
}
29
return await getLicenseBySubscriptionId(subscription_id, account_id);
30
} else {
31
throw Error("license_id or subscription_id must be specified");
32
}
33
}
34
35