mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-11-28 08:58:49 +02:00
improving configs
This commit is contained in:
parent
fa6a7c250a
commit
f8b4e1c968
1280
package-lock.json
generated
1280
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -43,7 +43,7 @@
|
||||
"sqlite3": "4.1.1",
|
||||
"ts-exif-parser": "0.1.4",
|
||||
"ts-node-iptc": "1.0.11",
|
||||
"typeconfig": "1.0.7",
|
||||
"typeconfig": "1.0.8c",
|
||||
"typeorm": "0.2.21",
|
||||
"winston": "2.4.4"
|
||||
},
|
||||
|
@ -2,27 +2,18 @@ import {UserDTO, UserRoles} from '../../../common/entities/UserDTO';
|
||||
import {IUserManager} from '../interfaces/IUserManager';
|
||||
import {ProjectPath} from '../../ProjectPath';
|
||||
import {Utils} from '../../../common/Utils';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import {PasswordHelper} from '../PasswordHelper';
|
||||
import {Config} from '../../../common/config/private/Config';
|
||||
|
||||
|
||||
export class UserManager implements IUserManager {
|
||||
private db: { users?: UserDTO[], idCounter?: number } = {};
|
||||
private readonly dbPath: string;
|
||||
|
||||
generateId(): string {
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
return s4() + s4() + s4() + s4();
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.dbPath = path.join(ProjectPath.Root, 'users.db');
|
||||
this.dbPath = ProjectPath.getAbsolutePath(Config.Server.Database.memory.usersFile);
|
||||
if (fs.existsSync(this.dbPath)) {
|
||||
this.loadDB();
|
||||
}
|
||||
|
@ -12,8 +12,22 @@ declare var process: NodeJS.Process;
|
||||
*/
|
||||
export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateConfig {
|
||||
|
||||
private static readonly CONFIG_PATH = path.join(__dirname, './../../../../config.json');
|
||||
private static CONFIG_PATH = path.join(__dirname, './../../../../config.json');
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// TODO: refactor this
|
||||
let configPath = process.argv.find(s => s.startsWith('--config-path='));
|
||||
if (configPath) {
|
||||
configPath = configPath.replace('--config-path=', '');
|
||||
if (path.isAbsolute(configPath)) {
|
||||
ConfigClass.CONFIG_PATH = configPath;
|
||||
} else {
|
||||
ConfigClass.CONFIG_PATH = path.join(__dirname, './../../../../', configPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setDatabaseType(type: ServerConfig.DatabaseType) {
|
||||
this.Server.Database.type = type;
|
||||
@ -30,7 +44,8 @@ export class ConfigClass extends PrivateConfigDefaultsClass implements IPrivateC
|
||||
['MYSQL_HOST', 'Server-Database-mysql-host'],
|
||||
['MYSQL_PASSWORD', 'Server-Database-mysql-password'],
|
||||
['MYSQL_USERNAME', 'Server-Database-mysql-username'],
|
||||
['MYSQL_DATABASE', 'Server-Database-mysql-database']]);
|
||||
['MYSQL_DATABASE', 'Server-Database-mysql-database']],
|
||||
process.argv.indexOf('--force-rewrite-config') !== -1);
|
||||
this.removeComment();
|
||||
|
||||
if (process.argv.indexOf('--config-only') !== -1) {
|
||||
|
@ -31,10 +31,15 @@ export module ServerConfig {
|
||||
storage: string;
|
||||
}
|
||||
|
||||
export interface MemoryConfig {
|
||||
usersFile: string;
|
||||
}
|
||||
|
||||
export interface DataBaseConfig {
|
||||
type: DatabaseType;
|
||||
mysql?: MySQLConfig;
|
||||
sqlite?: SQLiteConfig;
|
||||
memory?: MemoryConfig;
|
||||
}
|
||||
|
||||
export interface ThumbnailConfig {
|
||||
|
@ -35,6 +35,9 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr
|
||||
},
|
||||
sqlite: {
|
||||
storage: 'sqlite.db'
|
||||
},
|
||||
memory: {
|
||||
usersFile: 'user.db'
|
||||
}
|
||||
},
|
||||
Sharing: {
|
||||
|
Loading…
Reference in New Issue
Block a user