2018-05-13 00:19:51 +08:00
|
|
|
import {PublicConfigClass} from '../public/ConfigClass';
|
2019-02-07 23:44:51 +08:00
|
|
|
import {
|
|
|
|
DatabaseType,
|
|
|
|
IPrivateConfig,
|
|
|
|
LogLevel,
|
|
|
|
ReIndexingSensitivity,
|
|
|
|
ServerConfig,
|
|
|
|
SQLLogLevel,
|
|
|
|
ThumbnailProcessingLib
|
|
|
|
} from './IPrivateConfig';
|
2018-05-13 00:19:51 +08:00
|
|
|
import * as path from 'path';
|
|
|
|
import {ConfigLoader} from 'typeconfig';
|
2018-12-05 05:08:13 +08:00
|
|
|
import {Utils} from '../../Utils';
|
|
|
|
import {UserRoles} from '../../entities/UserDTO';
|
2017-06-04 21:25:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This configuration will be only at backend
|
|
|
|
*/
|
2017-07-08 18:43:42 +08:00
|
|
|
export class PrivateConfigClass extends PublicConfigClass implements IPrivateConfig {
|
2017-06-04 21:25:08 +08:00
|
|
|
|
2017-06-12 05:33:47 +08:00
|
|
|
public Server: ServerConfig = {
|
|
|
|
port: 80,
|
2018-12-28 05:14:32 +08:00
|
|
|
host: '0.0.0.0',
|
2018-05-13 00:19:51 +08:00
|
|
|
imagesFolder: 'demo/images',
|
2017-06-12 05:33:47 +08:00
|
|
|
thumbnail: {
|
2018-05-13 00:19:51 +08:00
|
|
|
folder: 'demo/TEMP',
|
2017-06-12 05:33:47 +08:00
|
|
|
processingLibrary: ThumbnailProcessingLib.sharp,
|
2019-02-15 07:25:55 +08:00
|
|
|
qualityPriority: true,
|
|
|
|
personFaceMargin: 0.6
|
2017-06-12 05:33:47 +08:00
|
|
|
},
|
2019-02-07 23:44:51 +08:00
|
|
|
log: {
|
|
|
|
level: LogLevel.info,
|
|
|
|
sqlLevel: SQLLogLevel.error
|
|
|
|
},
|
2017-07-16 16:59:28 +08:00
|
|
|
sessionTimeout: 1000 * 60 * 60 * 24 * 7,
|
2018-12-04 20:21:45 +08:00
|
|
|
photoMetadataSize: 512 * 1024,
|
2017-06-12 05:33:47 +08:00
|
|
|
database: {
|
2017-07-21 05:37:10 +08:00
|
|
|
type: DatabaseType.sqlite,
|
2017-06-12 05:33:47 +08:00
|
|
|
mysql: {
|
2018-05-13 00:19:51 +08:00
|
|
|
host: '',
|
|
|
|
username: '',
|
|
|
|
password: '',
|
|
|
|
database: ''
|
2017-06-04 21:25:08 +08:00
|
|
|
|
2017-07-21 05:37:10 +08:00
|
|
|
},
|
|
|
|
sqlite: {
|
2018-05-13 00:19:51 +08:00
|
|
|
storage: 'sqlite.db'
|
2017-06-12 05:33:47 +08:00
|
|
|
}
|
|
|
|
},
|
2017-07-04 01:17:49 +08:00
|
|
|
sharing: {
|
|
|
|
updateTimeout: 1000 * 60 * 5
|
|
|
|
},
|
2018-11-02 23:24:37 +08:00
|
|
|
threading: {
|
|
|
|
enable: true,
|
|
|
|
thumbnailThreads: 0
|
|
|
|
},
|
2017-07-28 05:10:16 +08:00
|
|
|
indexing: {
|
|
|
|
folderPreviewSize: 2,
|
|
|
|
cachedFolderTimeout: 1000 * 60 * 60,
|
2019-01-07 06:15:52 +08:00
|
|
|
reIndexingSensitivity: ReIndexingSensitivity.low
|
2019-01-19 07:18:20 +08:00
|
|
|
},
|
|
|
|
duplicates: {
|
|
|
|
listingLimit: 1000
|
2018-11-02 23:24:37 +08:00
|
|
|
}
|
2017-06-12 05:33:47 +08:00
|
|
|
};
|
2017-07-08 18:43:42 +08:00
|
|
|
private ConfigLoader: any;
|
2017-06-04 21:25:08 +08:00
|
|
|
|
2017-06-12 05:33:47 +08:00
|
|
|
public setDatabaseType(type: DatabaseType) {
|
|
|
|
this.Server.database.type = type;
|
|
|
|
if (type === DatabaseType.memory) {
|
2017-07-14 05:39:09 +08:00
|
|
|
this.Client.Search.enabled = false;
|
|
|
|
this.Client.Sharing.enabled = false;
|
2017-06-04 21:25:08 +08:00
|
|
|
}
|
2017-06-12 05:33:47 +08:00
|
|
|
}
|
2017-06-04 21:25:08 +08:00
|
|
|
|
2017-07-08 18:43:42 +08:00
|
|
|
public load() {
|
2019-07-19 22:03:50 +08:00
|
|
|
this.addComment();
|
2017-07-08 18:43:42 +08:00
|
|
|
ConfigLoader.loadBackendConfig(this,
|
|
|
|
path.join(__dirname, './../../../config.json'),
|
2019-01-28 04:10:01 +08:00
|
|
|
[['PORT', 'Server-port'],
|
|
|
|
['MYSQL_HOST', 'Server-database-mysql-host'],
|
|
|
|
['MYSQL_PASSWORD', 'Server-database-mysql-password'],
|
|
|
|
['MYSQL_USERNAME', 'Server-database-mysql-username'],
|
|
|
|
['MYSQL_DATABASE', 'Server-database-mysql-database']]);
|
2019-07-19 22:03:50 +08:00
|
|
|
this.removeComment();
|
2017-07-08 18:43:42 +08:00
|
|
|
|
2018-12-05 05:08:13 +08: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);
|
|
|
|
}
|
2019-02-07 23:44:51 +08:00
|
|
|
if (Utils.enumToArray(LogLevel).map(r => r.key).indexOf(this.Server.log.level) === -1) {
|
|
|
|
throw new Error('Unknown Server.log.level, found: ' + this.Server.log.level);
|
|
|
|
}
|
|
|
|
if (Utils.enumToArray(SQLLogLevel).map(r => r.key).indexOf(this.Server.log.sqlLevel) === -1) {
|
|
|
|
throw new Error('Unknown Server.log.level, found: ' + this.Server.log.sqlLevel);
|
|
|
|
}
|
2018-12-05 05:08:13 +08:00
|
|
|
|
2017-07-08 18:43:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public save() {
|
2018-12-02 19:22:05 +08:00
|
|
|
try {
|
2019-07-19 22:03:50 +08:00
|
|
|
this.addComment();
|
2018-12-02 19:22:05 +08:00
|
|
|
ConfigLoader.saveConfigFile(path.join(__dirname, './../../../config.json'), this);
|
2019-07-19 22:03:50 +08:00
|
|
|
this.removeComment();
|
2018-12-02 19:22:05 +08:00
|
|
|
} catch (e) {
|
|
|
|
throw new Error('Error during saving config: ' + e.toString());
|
|
|
|
}
|
2017-07-08 18:43:42 +08:00
|
|
|
}
|
2017-07-13 00:31:19 +08:00
|
|
|
|
|
|
|
public original(): PrivateConfigClass {
|
2018-05-13 00:19:51 +08:00
|
|
|
const cfg = new PrivateConfigClass();
|
2017-07-13 00:31:19 +08:00
|
|
|
cfg.load();
|
|
|
|
return cfg;
|
|
|
|
}
|
2019-07-19 22:03:50 +08:00
|
|
|
|
|
|
|
private addComment() {
|
|
|
|
(<any>this)['__NOTE'] = 'NOTE: this config is not intended for manual edit, ' +
|
|
|
|
'use the app UI instead as it has comments and descriptions.';
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeComment() {
|
|
|
|
delete (<any>this)['__NOTE'];
|
|
|
|
}
|
2017-06-04 21:25:08 +08:00
|
|
|
}
|
|
|
|
|