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