1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Merge pull request #889 from bpatrik/bugfix/config-defaults

Fix config default loading #888
This commit is contained in:
Patrik J. Braun 2024-04-15 21:22:20 +02:00 committed by GitHub
commit 1e4a6d4aef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 4 deletions

View File

@ -22,9 +22,8 @@ export class ExtensionConfigWrapper {
// make sure the config file exists by the time we load it. // make sure the config file exists by the time we load it.
// TODO: remove this once typeconfig is fixed and can properly load defaults in arrays // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) { if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
await pc.save(); await pc.load();
} }
await pc.load(); // loading the basic configs, but we do not know the extension config hierarchy yet await pc.load(); // loading the basic configs, but we do not know the extension config hierarchy yet
// TODO make sure that all extensions are present even after loading them from file // TODO make sure that all extensions are present even after loading them from file
@ -47,7 +46,7 @@ export class ExtensionConfigWrapper {
// make sure the config file exists by the time we load it. // make sure the config file exists by the time we load it.
// TODO: remove this once typeconfig is fixed and can properly load defaults in arrays // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) { if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
pc.saveSync(); pc.loadSync();
} }
pc.loadSync(); // loading the basic configs, but we do not know the extension config hierarchy yet pc.loadSync(); // loading the basic configs, but we do not know the extension config hierarchy yet
// TODO make sure that all extensions are present even after loading them from file // TODO make sure that all extensions are present even after loading them from file

View File

@ -15,7 +15,7 @@ const isTesting = process.env['NODE_ENV'] == true || ['afterEach', 'after', 'bef
.every((fn) => (global as any)[fn] instanceof Function); .every((fn) => (global as any)[fn] instanceof Function);
@ConfigClass<IConfigClass<TAGS> & ServerConfig>({ @ConfigClass<IConfigClass<TAGS> & ServerConfig>({
configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/backend/tmp/config.json'), configPath: path.join(__dirname, !isTesting ? './../../../../config.json' : './../../../../test/tmp/config.json'),
crateConfigPathIfNotExists: isTesting, crateConfigPathIfNotExists: isTesting,
saveIfNotExist: true, saveIfNotExist: true,
attachDescription: true, attachDescription: true,

View File

@ -0,0 +1,25 @@
import {expect} from 'chai';
import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigWrapper} from '../../../../src/backend/model/extension/ExtensionConfigWrapper';
import {TestHelper} from '../../../TestHelper';
import * as fs from 'fs';
describe('Config', () => {
beforeEach(async () => {
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
});
afterEach(async () => {
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
});
it('should load default from env', () => {
process.env['default-Media-tempFolder'] = 'test/test';
const conf = ExtensionConfigWrapper.originalSync();
expect(conf.Media.tempFolder).to.be.equal('test/test');
expect(ConfigClassBuilder.attachPrivateInterface(conf.Media).__defaults.tempFolder).to.be.equal('test/test');
expect(process.env['default-Media-tempFolder']).to.be.equal('test/test');
const conf2 = ExtensionConfigWrapper.originalSync();
expect(ConfigClassBuilder.attachPrivateInterface(conf2.Media).__defaults.tempFolder).to.be.equal('test/test');
expect(conf2.Media.tempFolder).to.be.equal('test/test');
});
});