1
0
Fork 0
mirror of synced 2024-09-30 00:57:16 +13:00
budibase/packages/worker/src/api/controllers/global/license.ts

84 lines
2 KiB
TypeScript
Raw Normal View History

import { licensing, quotas } from "@budibase/pro"
import {
ActivateLicenseKeyRequest,
2023-07-11 03:12:19 +12:00
ActivateOfflineLicenseTokenRequest,
GetLicenseKeyResponse,
GetOfflineIdentifierResponse,
2023-07-11 03:12:19 +12:00
GetOfflineLicenseTokenResponse,
UserCtx,
} from "@budibase/types"
2022-03-10 10:16:22 +13:00
// LICENSE KEY
2022-03-10 10:16:22 +13:00
2023-07-15 03:55:48 +12:00
export async function activateLicenseKey(
ctx: UserCtx<ActivateLicenseKeyRequest>
) {
const { licenseKey } = ctx.request.body
2023-07-07 22:48:12 +12:00
await licensing.keys.activateLicenseKey(licenseKey)
2022-03-10 10:16:22 +13:00
ctx.status = 200
}
export async function getLicenseKey(ctx: UserCtx<void, GetLicenseKeyResponse>) {
2023-07-07 22:48:12 +12:00
const licenseKey = await licensing.keys.getLicenseKey()
if (licenseKey) {
ctx.body = { licenseKey: "*" }
ctx.status = 200
} else {
ctx.status = 404
}
}
export async function deleteLicenseKey(ctx: UserCtx<void, void>) {
2023-07-07 22:48:12 +12:00
await licensing.keys.deleteLicenseKey()
ctx.status = 204
}
// OFFLINE LICENSE
2023-07-15 03:55:48 +12:00
export async function activateOfflineLicenseToken(
ctx: UserCtx<ActivateOfflineLicenseTokenRequest>
) {
const { offlineLicenseToken } = ctx.request.body
2023-07-11 03:12:19 +12:00
await licensing.offline.activateOfflineLicenseToken(offlineLicenseToken)
2022-03-10 10:16:22 +13:00
ctx.status = 200
}
2023-07-15 03:55:48 +12:00
export async function getOfflineLicenseToken(
ctx: UserCtx<void, GetOfflineLicenseTokenResponse>
) {
2023-07-07 22:48:12 +12:00
const offlineLicenseToken = await licensing.offline.getOfflineLicenseToken()
if (offlineLicenseToken) {
ctx.body = { offlineLicenseToken: "*" }
ctx.status = 200
} else {
ctx.status = 404
2022-03-10 10:16:22 +13:00
}
}
2022-03-15 21:16:45 +13:00
2023-07-11 03:12:19 +12:00
export async function deleteOfflineLicenseToken(ctx: UserCtx<void, void>) {
2023-07-07 22:48:12 +12:00
await licensing.offline.deleteOfflineLicenseToken()
ctx.status = 204
}
2023-07-15 03:55:48 +12:00
export async function getOfflineLicenseIdentifier(
ctx: UserCtx<void, GetOfflineIdentifierResponse>
) {
const identifierBase64 = await licensing.offline.getIdentifierBase64()
ctx.body = { identifierBase64 }
ctx.status = 200
}
// LICENSES
export const refresh = async (ctx: any) => {
await licensing.cache.refresh()
ctx.status = 200
}
// USAGE
2022-03-15 21:16:45 +13:00
export const getQuotaUsage = async (ctx: any) => {
ctx.body = await quotas.getQuotaUsage()
2023-07-08 07:07:15 +12:00
ctx.status = 200
2022-03-15 21:16:45 +13:00
}