Skip to content

Commit

Permalink
Merge pull request #885 from bpatrik/bugfix/ext-config
Browse files Browse the repository at this point in the history
Improve extansion loading #847
  • Loading branch information
bpatrik authored Apr 12, 2024
2 parents 8c86dcb + 94d3271 commit 479257a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"nodemailer": "6.9.4",
"reflect-metadata": "0.1.13",
"sharp": "0.31.3",
"typeconfig": "2.2.11",
"ts-node-iptc": "1.0.11",
"typeconfig": "2.2.13",
"typeorm": "0.3.12",
"xml2js": "0.6.2"
},
Expand Down
14 changes: 14 additions & 0 deletions src/backend/model/extension/ExtensionConfigWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {PrivateConfigClass} from '../../../common/config/private/PrivateConfigCl
import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigTemplateLoader} from './ExtensionConfigTemplateLoader';
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]';
Expand All @@ -16,6 +19,12 @@ export class ExtensionConfigWrapper {
const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
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

} catch (e) {
Expand All @@ -34,6 +43,11 @@ export class ExtensionConfigWrapper {
const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
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

} catch (e) {
Expand Down
6 changes: 2 additions & 4 deletions test/backend/integration/routers/admin/SettingsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ describe('SettingsRouter', () => {
attachVolatile: true,
skipTags: {secret: true} as TAGS
})));
//TODO: fix broken test.
// It breaks if config. sets value through constructor
/*

const result = await chai.request(server.Server)
.get(Config.Server.apiPath + '/settings');

result.res.should.have.status(200);
result.body.should.be.a('object');
should.equal(result.body.error, null);
(result.body.result as ServerConfig).Environment.upTime = null;
result.body.result.should.deep.equal(originalJSON);*/
result.body.result.should.deep.equal(originalJSON);
});
});
});
26 changes: 26 additions & 0 deletions test/backend/unit/model/extension/ExtensionConfigWrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 479257a

Please sign in to comment.