1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

66 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-01-28 18:36:52 +01:00
import {IPrivateConfig, ServerConfig} from './PrivateConfig';
import {ClientConfig} from '../public/ClientConfig';
import * as crypto from 'crypto';
import * as path from 'path';
2020-02-04 19:37:47 +01:00
import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node';
import {ConfigProperty, IConfigClass} from 'typeconfig/common';
2017-06-04 15:25:08 +02:00
2020-02-07 23:32:41 +01:00
declare const process: any;
2020-09-10 19:40:44 +02:00
consts upTime = (new Date()).toISOString();
2020-01-28 18:36:52 +01:00
@ConfigClass({
configPath: path.join(__dirname, './../../../../config.json'),
saveIfNotExist: true,
attachDescription: true,
enumsAsString: true,
2020-02-06 22:46:45 +01:00
softReadonly: true,
2020-01-28 18:36:52 +01:00
cli: {
enable: {
configPath: true,
2020-02-04 19:37:47 +01:00
attachState: true,
2020-01-28 18:36:52 +01:00
attachDescription: true,
rewriteCLIConfig: true,
rewriteENVConfig: true,
enumsAsString: true,
saveIfNotExist: true,
exitOnConfig: true
},
defaults: {
enabled: true
}
}
})
export class PrivateConfigClass implements IPrivateConfig {
2020-02-07 13:59:36 +01:00
@ConfigProperty({type: ServerConfig.Config})
2020-01-28 18:36:52 +01:00
Server: ServerConfig.Config = new ServerConfig.Config();
2020-02-07 13:59:36 +01:00
@ConfigProperty({type: ClientConfig.Config})
2020-02-04 19:37:47 +01:00
Client: IConfigClass & ClientConfig.Config = <IConfigClass & ClientConfig.Config>(new ClientConfig.Config());
2020-01-28 18:36:52 +01:00
constructor() {
if (!this.Server.sessionSecret || this.Server.sessionSecret.length === 0) {
this.Server.sessionSecret = [crypto.randomBytes(256).toString('hex'),
crypto.randomBytes(256).toString('hex'),
crypto.randomBytes(256).toString('hex')];
}
2020-02-07 23:32:41 +01:00
this.Server.Environment.appVersion = require('../../../../package.json').version;
this.Server.Environment.buildTime = require('../../../../package.json').buildTime;
this.Server.Environment.buildCommitHash = require('../../../../package.json').buildCommitHash;
2020-09-10 19:40:44 +02:00
this.Server.Environment.upTime = upTime;
2020-02-07 23:32:41 +01:00
this.Server.Environment.isDocker = !!process.env['PI_DOCKER'];
2020-01-28 18:36:52 +01:00
}
2020-02-07 23:32:41 +01:00
2020-01-28 18:36:52 +01:00
async original(): Promise<PrivateConfigClass & IConfigClass> {
const pc = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
await pc.load();
return pc;
}
}
export const Config = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
Config.loadSync();