mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-16 15:50:09 +02:00
Add license tiers
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
LicenseStatus
|
||||
} from "@server/license/license";
|
||||
import { setHostMeta } from "@server/lib/hostMeta";
|
||||
import { build } from "@server/build";
|
||||
|
||||
type ActivateLicenseKeyAPIResponse = {
|
||||
data: {
|
||||
@@ -119,6 +120,9 @@ LQIDAQAB
|
||||
}
|
||||
|
||||
public async isUnlocked(): Promise<boolean> {
|
||||
if (build == "saas") {
|
||||
return true;
|
||||
}
|
||||
const status = await this.check();
|
||||
if (status.isHostLicensed) {
|
||||
if (status.isLicenseValid) {
|
||||
@@ -128,6 +132,20 @@ LQIDAQAB
|
||||
return false;
|
||||
}
|
||||
|
||||
public async hasTier(tier: LicenseKeyTier[]): Promise<boolean> {
|
||||
if (build == "saas") {
|
||||
return true;
|
||||
}
|
||||
const status = await this.check();
|
||||
if (status.isHostLicensed && status.isLicenseValid) {
|
||||
return (
|
||||
status.tier !== undefined &&
|
||||
tier.includes(status.tier as LicenseKeyTier)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async check(): Promise<LicenseStatus> {
|
||||
// If a check is already in progress, return the last known status
|
||||
if (this.checkInProgress) {
|
||||
@@ -135,8 +153,7 @@ LQIDAQAB
|
||||
"License check already in progress, returning last known status"
|
||||
);
|
||||
const lastStatus = this.statusCache.get(this.statusKey) as
|
||||
| LicenseStatus
|
||||
| undefined;
|
||||
LicenseStatus | undefined;
|
||||
if (lastStatus) {
|
||||
return lastStatus;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user