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

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-04 19:37:31 +02:00
import { IPrivateConfig, ServerConfig } from './PrivateConfig';
import { ClientConfig } from '../public/ClientConfig';
2020-01-28 18:36:52 +01:00
import * as crypto from 'crypto';
import * as path from 'path';
2022-04-04 19:37:31 +02: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;
2022-04-04 19:37:31 +02:00
const upTime = new Date().toISOString();
2020-09-10 19:40:44 +02:00
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,
2022-04-04 19:37:31 +02:00
exitOnConfig: true,
2020-01-28 18:36:52 +01:00
},
defaults: {
2022-04-04 19:37:31 +02:00
enabled: true,
},
},
2020-01-28 18:36:52 +01:00
})
export class PrivateConfigClass implements IPrivateConfig {
2022-04-04 19:37:31 +02:00
@ConfigProperty({ type: ServerConfig })
Server: ServerConfig = new ServerConfig();
2022-04-04 19:37:31 +02:00
@ConfigProperty({ type: ClientConfig })
Client: IConfigClass & ClientConfig = new ClientConfig() as IConfigClass &
ClientConfig;
2020-01-28 18:36:52 +01:00
constructor() {
if (!this.Server.sessionSecret || this.Server.sessionSecret.length === 0) {
2022-04-04 19:37:31 +02:00
this.Server.sessionSecret = [
2020-01-28 18:36:52 +01:00
crypto.randomBytes(256).toString('hex'),
2022-04-04 19:37:31 +02:00
crypto.randomBytes(256).toString('hex'),
crypto.randomBytes(256).toString('hex'),
];
2020-01-28 18:36:52 +01:00
}
2020-02-07 23:32:41 +01:00
2022-04-04 19:37:31 +02: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;
2021-04-17 15:40:01 +02:00
this.Server.Environment.isDocker = !!process.env.PI_DOCKER;
2020-01-28 18:36:52 +01:00
}
async original(): Promise<PrivateConfigClass & IConfigClass> {
const pc = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
await pc.load();
return pc;
}
}
2022-04-04 19:37:31 +02:00
export const Config = ConfigClassBuilder.attachInterface(
new PrivateConfigClass()
);
2020-01-28 18:36:52 +01:00
Config.loadSync();