mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for installing self-hosted team licenses via encrypted license files. - Introduced a new "Onetime" license variant for self-hosted environments. - Added a GraphQL mutation to upload and install license files. - License details now display the license variant. - **Bug Fixes** - Improved error messages for license activation and expiration, including dynamic reasons. - **Localization** - Updated and improved license-related error messages for better clarity. - **Tests** - Added comprehensive end-to-end tests for license installation scenarios. - **Chores** - Enhanced environment variable handling and public key management for license verification. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
39 lines
943 B
TypeScript
39 lines
943 B
TypeScript
import 'reflect-metadata';
|
|
|
|
import { existsSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
import { config } from 'dotenv';
|
|
|
|
import { createGlobalEnv } from './env';
|
|
|
|
function loadPrivateKey() {
|
|
const file = join(CUSTOM_CONFIG_PATH, 'private.key');
|
|
if (!process.env.AFFINE_PRIVATE_KEY && existsSync(file)) {
|
|
const privateKey = readFileSync(file, 'utf-8');
|
|
process.env.AFFINE_PRIVATE_KEY = privateKey;
|
|
}
|
|
}
|
|
|
|
function load() {
|
|
let isPrivateKeyFromEnv = !!process.env.AFFINE_PRIVATE_KEY;
|
|
// load `.env` under pwd
|
|
config();
|
|
// load `.env` under user config folder
|
|
config({
|
|
path: join(CUSTOM_CONFIG_PATH, '.env'),
|
|
});
|
|
|
|
// The old AFFINE_PRIVATE_KEY in old .env is somehow not working,
|
|
// we should ignore it
|
|
if (!isPrivateKeyFromEnv) {
|
|
delete process.env.AFFINE_PRIVATE_KEY;
|
|
}
|
|
|
|
// 2. load `config/private.key` to patch app configs
|
|
loadPrivateKey();
|
|
}
|
|
|
|
load();
|
|
createGlobalEnv();
|