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