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-01-28 18:36:52 +01:00
|
|
|
@ConfigClass({
|
|
|
|
configPath: path.join(__dirname, './../../../../config.json'),
|
|
|
|
saveIfNotExist: true,
|
|
|
|
attachDescription: true,
|
|
|
|
enumsAsString: true,
|
|
|
|
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 {
|
|
|
|
@ConfigProperty()
|
|
|
|
Server: ServerConfig.Config = new ServerConfig.Config();
|
|
|
|
@ConfigProperty()
|
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')];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|