mirror of
https://github.com/docmost/docmost.git
synced 2026-06-11 02:36:56 +08:00
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ModuleRef } from '@nestjs/core';
|
|
import { EnvironmentService } from './environment.service';
|
|
|
|
@Injectable()
|
|
export class LicenseCheckService {
|
|
constructor(
|
|
private moduleRef: ModuleRef,
|
|
private environmentService: EnvironmentService,
|
|
) {}
|
|
|
|
isValidEELicense(licenseKey: string): boolean {
|
|
if (this.environmentService.isCloud()) {
|
|
return true;
|
|
}
|
|
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
const LicenseModule = require('../../ee/licence/license.service');
|
|
const licenseService = this.moduleRef.get(LicenseModule.LicenseService, {
|
|
strict: false,
|
|
});
|
|
return licenseService.isValidEELicense(licenseKey);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
hasFeature(licenseKey: string, feature: string): boolean {
|
|
if (this.environmentService.isCloud()) {
|
|
return true;
|
|
}
|
|
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
const LicenseModule = require('../../ee/licence/license.service');
|
|
const licenseService = this.moduleRef.get(LicenseModule.LicenseService, {
|
|
strict: false,
|
|
});
|
|
return licenseService.hasFeature(licenseKey, feature);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
getFeatures(licenseKey: string): string[] {
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
const LicenseModule = require('../../ee/licence/license.service');
|
|
const licenseService = this.moduleRef.get(LicenseModule.LicenseService, {
|
|
strict: false,
|
|
});
|
|
return licenseService.getFeatures(licenseKey);
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
resolveFeatures(licenseKey: string, plan: string): string[] {
|
|
if (this.environmentService.isCloud()) {
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
const { getFeaturesForCloudPlan } = require('../../ee/licence/feature-registry');
|
|
return [...getFeaturesForCloudPlan(plan)];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
return this.getFeatures(licenseKey);
|
|
}
|
|
}
|