1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-02 03:37:54 +02:00

Merge pull request #885 from bpatrik/bugfix/ext-config

Improve extansion loading #847
This commit is contained in:
Patrik J. Braun 2024-04-12 23:41:14 +02:00 committed by GitHub
commit 479257a3e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 12 deletions

15
package-lock.json generated
View File

@ -26,7 +26,8 @@
"nodemailer": "6.9.4", "nodemailer": "6.9.4",
"reflect-metadata": "0.1.13", "reflect-metadata": "0.1.13",
"sharp": "0.31.3", "sharp": "0.31.3",
"typeconfig": "2.2.11", "ts-node-iptc": "1.0.11",
"typeconfig": "2.2.13",
"typeorm": "0.3.12", "typeorm": "0.3.12",
"xml2js": "0.6.2" "xml2js": "0.6.2"
}, },
@ -20361,9 +20362,9 @@
} }
}, },
"node_modules/typeconfig": { "node_modules/typeconfig": {
"version": "2.2.11", "version": "2.2.13",
"resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-2.2.11.tgz", "resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-2.2.13.tgz",
"integrity": "sha512-Knj+1kbIJ4zOZlUm2TPSWZUoiOW4txrmPyf6oyuBhaDQDlGxpSL5jobF3vVV9mZElK1V3ZQVeTgvGaiDyeT8mQ==", "integrity": "sha512-eT9FqQVJTacuJELZ2XKN9s1phUnaceQd1NhzgTHZuULDWSOpcMTw8jRvg2Uyp14IRe9W9N8DOItz38QQJcwctQ==",
"dependencies": { "dependencies": {
"minimist": "1.2.8" "minimist": "1.2.8"
} }
@ -35282,9 +35283,9 @@
} }
}, },
"typeconfig": { "typeconfig": {
"version": "2.2.11", "version": "2.2.13",
"resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-2.2.11.tgz", "resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-2.2.13.tgz",
"integrity": "sha512-Knj+1kbIJ4zOZlUm2TPSWZUoiOW4txrmPyf6oyuBhaDQDlGxpSL5jobF3vVV9mZElK1V3ZQVeTgvGaiDyeT8mQ==", "integrity": "sha512-eT9FqQVJTacuJELZ2XKN9s1phUnaceQd1NhzgTHZuULDWSOpcMTw8jRvg2Uyp14IRe9W9N8DOItz38QQJcwctQ==",
"requires": { "requires": {
"minimist": "1.2.8" "minimist": "1.2.8"
} }

View File

@ -53,7 +53,8 @@
"nodemailer": "6.9.4", "nodemailer": "6.9.4",
"reflect-metadata": "0.1.13", "reflect-metadata": "0.1.13",
"sharp": "0.31.3", "sharp": "0.31.3",
"typeconfig": "2.2.11", "ts-node-iptc": "1.0.11",
"typeconfig": "2.2.13",
"typeorm": "0.3.12", "typeorm": "0.3.12",
"xml2js": "0.6.2" "xml2js": "0.6.2"
}, },

View File

@ -3,6 +3,9 @@ import {PrivateConfigClass} from '../../../common/config/private/PrivateConfigCl
import {ConfigClassBuilder} from 'typeconfig/node'; import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigTemplateLoader} from './ExtensionConfigTemplateLoader'; import {ExtensionConfigTemplateLoader} from './ExtensionConfigTemplateLoader';
import {NotificationManager} from '../NotifocationManager'; import {NotificationManager} from '../NotifocationManager';
import {ServerConfig} from '../../../common/config/private/PrivateConfig';
import {ConfigClassOptions} from 'typeconfig/src/decorators/class/IConfigClass';
import * as fs from 'fs';
const LOG_TAG = '[ExtensionConfigWrapper]'; const LOG_TAG = '[ExtensionConfigWrapper]';
@ -16,6 +19,12 @@ export class ExtensionConfigWrapper {
const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass()); const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc); ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
try { try {
// 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
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
await pc.save();
}
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
} catch (e) { } catch (e) {
@ -34,6 +43,11 @@ export class ExtensionConfigWrapper {
const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass()); const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc); ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
try { try {
// 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
if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
pc.saveSync();
}
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
} catch (e) { } catch (e) {

View File

@ -48,9 +48,7 @@ describe('SettingsRouter', () => {
attachVolatile: true, attachVolatile: true,
skipTags: {secret: true} as TAGS skipTags: {secret: true} as TAGS
}))); })));
//TODO: fix broken test.
// It breaks if config. sets value through constructor
/*
const result = await chai.request(server.Server) const result = await chai.request(server.Server)
.get(Config.Server.apiPath + '/settings'); .get(Config.Server.apiPath + '/settings');
@ -58,7 +56,7 @@ describe('SettingsRouter', () => {
result.body.should.be.a('object'); result.body.should.be.a('object');
should.equal(result.body.error, null); should.equal(result.body.error, null);
(result.body.result as ServerConfig).Environment.upTime = null; (result.body.result as ServerConfig).Environment.upTime = null;
result.body.result.should.deep.equal(originalJSON);*/ result.body.result.should.deep.equal(originalJSON);
}); });
}); });
}); });

View File

@ -0,0 +1,26 @@
import {expect} from 'chai';
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
import {TAGS} from '../../../../../src/common/config/public/ClientConfig';
// to help WebStorm to handle the test cases
declare let describe: any;
declare const after: any;
declare const before: any;
declare const it: any;
describe('ExtensionConfigWrapper', () => {
it('should load original config multiple times with the same result', async () => {
const get = async () => JSON.parse(JSON.stringify((await ExtensionConfigWrapper.original()).toJSON({
attachState: true,
attachVolatile: true,
skipTags: {secret: true} as TAGS
})));
const a = await get();
const b = await get();
expect(b).to.deep.equal(a);
const c = await get();
expect(c).to.deep.equal(a);
});
});