1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02:00

Check if folder exists before listing it.

This commit is contained in:
Patrik J. Braun 2024-03-25 21:47:05 +01:00
parent 743d29b208
commit 7f65dfd1b2

View File

@ -40,34 +40,36 @@ export class ExtensionConfigTemplateLoader {
// already loaded
if (!this.loaded) {
this.extensionList = (fs
.readdirSync(this.extensionsFolder))
.filter((f): boolean =>
fs.statSync(path.join(this.extensionsFolder, f)).isDirectory()
);
this.extensionList.sort();
this.extensionTemplates = [];
for (let i = 0; i < this.extensionList.length; ++i) {
const extFolder = this.extensionList[i];
const extPath = path.join(this.extensionsFolder, extFolder);
const serverExtPath = path.join(extPath, 'server.js');
if (!fs.existsSync(serverExtPath)) {
continue;
}
if (fs.existsSync(this.extensionsFolder)) {
this.extensionList = (fs
.readdirSync(this.extensionsFolder))
.filter((f): boolean =>
fs.statSync(path.join(this.extensionsFolder, f)).isDirectory()
);
this.extensionList.sort();
for (let i = 0; i < this.extensionList.length; ++i) {
const extFolder = this.extensionList[i];
const extPath = path.join(this.extensionsFolder, extFolder);
const serverExtPath = path.join(extPath, 'server.js');
if (!fs.existsSync(serverExtPath)) {
continue;
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ext = require(serverExtPath);
if (typeof ext?.initConfig === 'function') {
ext?.initConfig({
setConfigTemplate: (template: { new(): unknown }): void => {
this.extensionTemplates.push({folder: extFolder, template: template});
}
});
} else {
//also create basic config extensions that do not have any
this.extensionTemplates.push({folder: extFolder});
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ext = require(serverExtPath);
if (typeof ext?.initConfig === 'function') {
ext?.initConfig({
setConfigTemplate: (template: { new(): unknown }): void => {
this.extensionTemplates.push({folder: extFolder, template: template});
}
});
} else {
//also create basic config extensions that do not have any
this.extensionTemplates.push({folder: extFolder});
}
}
}
this.loaded = true;
@ -77,8 +79,6 @@ export class ExtensionConfigTemplateLoader {
}
private setTemplatesToConfig(config: PrivateConfigClass) {
if (!this.extensionTemplates) {
return;
@ -100,7 +100,7 @@ export class ExtensionConfigTemplateLoader {
if (!c) {
c = new ServerExtensionsEntryConfig(ext.folder);
if (ext.template) {
c.configs= new ext.template()
c.configs = new ext.template();
}
config.Extensions.extensions.push(c);
}