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

86 lines
2.2 KiB
TypeScript
Raw Normal View History

import {PublicConfigClass} from '../public/ConfigClass';
import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ServerConfig, ThumbnailProcessingLib} from './IPrivateConfig';
import * as path from 'path';
import {ConfigLoader} from 'typeconfig';
import {Utils} from '../../Utils';
import {UserRoles} from '../../entities/UserDTO';
2017-06-04 15:25:08 +02:00
/**
* This configuration will be only at backend
*/
2017-07-08 12:43:42 +02:00
export class PrivateConfigClass extends PublicConfigClass implements IPrivateConfig {
2017-06-04 15:25:08 +02:00
public Server: ServerConfig = {
port: 80,
2018-12-27 22:14:32 +01:00
host: '0.0.0.0',
imagesFolder: 'demo/images',
thumbnail: {
folder: 'demo/TEMP',
processingLibrary: ThumbnailProcessingLib.sharp,
qualityPriority: true
},
sessionTimeout: 1000 * 60 * 60 * 24 * 7,
2018-12-04 13:21:45 +01:00
photoMetadataSize: 512 * 1024,
database: {
type: DatabaseType.sqlite,
mysql: {
host: '',
username: '',
password: '',
database: ''
2017-06-04 15:25:08 +02:00
},
sqlite: {
storage: 'sqlite.db'
}
},
2017-07-03 19:17:49 +02:00
sharing: {
updateTimeout: 1000 * 60 * 5
},
threading: {
enable: true,
thumbnailThreads: 0
},
2017-07-27 23:10:16 +02:00
indexing: {
folderPreviewSize: 2,
cachedFolderTimeout: 1000 * 60 * 60,
reIndexingSensitivity: ReIndexingSensitivity.low
}
};
2017-07-08 12:43:42 +02:00
private ConfigLoader: any;
2017-06-04 15:25:08 +02:00
public setDatabaseType(type: DatabaseType) {
this.Server.database.type = type;
if (type === DatabaseType.memory) {
2017-07-13 23:39:09 +02:00
this.Client.Search.enabled = false;
this.Client.Sharing.enabled = false;
2017-06-04 15:25:08 +02:00
}
}
2017-06-04 15:25:08 +02:00
2017-07-08 12:43:42 +02:00
public load() {
ConfigLoader.loadBackendConfig(this,
path.join(__dirname, './../../../config.json'),
[['PORT', 'Server-port']]);
2017-07-08 12:43:42 +02:00
if (Utils.enumToArray(UserRoles).map(r => r.key).indexOf(this.Client.unAuthenticatedUserRole) === -1) {
throw new Error('Unknown user role for Client.unAuthenticatedUserRole, found: ' + this.Client.unAuthenticatedUserRole);
}
2017-07-08 12:43:42 +02:00
}
public save() {
2018-12-02 12:22:05 +01:00
try {
ConfigLoader.saveConfigFile(path.join(__dirname, './../../../config.json'), this);
} catch (e) {
throw new Error('Error during saving config: ' + e.toString());
}
2017-07-08 12:43:42 +02:00
}
2017-07-12 18:31:19 +02:00
public original(): PrivateConfigClass {
const cfg = new PrivateConfigClass();
2017-07-12 18:31:19 +02:00
cfg.load();
return cfg;
}
2017-06-04 15:25:08 +02:00
}