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

Init projectPath instead of extension manager for better path handling #847 #784 #897

This commit is contained in:
Patrik J. Braun 2024-04-29 19:46:28 +02:00
parent 012fc1f7b4
commit 278eb86579
3 changed files with 19 additions and 22 deletions

View File

@ -1,6 +1,6 @@
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import {Config} from '../common/config/private/Config'; import {PrivateConfigClass} from '../common/config/private/PrivateConfigClass';
export class ProjectPathClass { export class ProjectPathClass {
public Root: string; public Root: string;
@ -11,8 +11,10 @@ export class ProjectPathClass {
public FrontendFolder: string; public FrontendFolder: string;
public ExtensionFolder: string; public ExtensionFolder: string;
public DBFolder: string; public DBFolder: string;
private cfg: PrivateConfigClass;
constructor() { init(cfg: PrivateConfigClass) {
this.cfg = cfg;
this.reset(); this.reset();
} }
@ -31,12 +33,12 @@ export class ProjectPathClass {
reset(): void { reset(): void {
this.Root = path.join(__dirname, '/../../'); this.Root = path.join(__dirname, '/../../');
this.FrontendFolder = path.join(this.Root, 'dist'); this.FrontendFolder = path.join(this.Root, 'dist');
this.ImageFolder = this.getAbsolutePath(Config.Media.folder); this.ImageFolder = this.getAbsolutePath(this.cfg.Media.folder);
this.TempFolder = this.getAbsolutePath(Config.Media.tempFolder); this.TempFolder = this.getAbsolutePath(this.cfg.Media.tempFolder);
this.TranscodedFolder = path.join(this.TempFolder, 'tc'); this.TranscodedFolder = path.join(this.TempFolder, 'tc');
this.FacesFolder = path.join(this.TempFolder, 'f'); this.FacesFolder = path.join(this.TempFolder, 'f');
this.DBFolder = this.getAbsolutePath(Config.Database.dbFolder); this.DBFolder = this.getAbsolutePath(this.cfg.Database.dbFolder);
this.ExtensionFolder = this.getAbsolutePath(Config.Extensions.folder); this.ExtensionFolder = this.getAbsolutePath(this.cfg.Extensions.folder);
// create thumbnail folder if not exist // create thumbnail folder if not exist
if (!fs.existsSync(this.TempFolder)) { if (!fs.existsSync(this.TempFolder)) {

View File

@ -2,11 +2,8 @@ import {PrivateConfigClass} from '../../../common/config/private/PrivateConfigCl
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig'; import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig';
import * as child_process from 'child_process'; import {ProjectPath} from '../../ProjectPath';
const execSync = child_process.execSync;
const LOG_TAG = '[ExtensionConfigTemplateLoader]';
/** /**
* This class decouples the extension management and the config. * This class decouples the extension management and the config.
@ -16,7 +13,6 @@ const LOG_TAG = '[ExtensionConfigTemplateLoader]';
export class ExtensionConfigTemplateLoader { export class ExtensionConfigTemplateLoader {
private static instance: ExtensionConfigTemplateLoader; private static instance: ExtensionConfigTemplateLoader;
private extensionsFolder: string;
private loaded = false; private loaded = false;
private extensionList: string[] = []; private extensionList: string[] = [];
@ -31,29 +27,26 @@ export class ExtensionConfigTemplateLoader {
} }
init(extensionsFolder: string) {
this.extensionsFolder = extensionsFolder;
}
public loadExtensionTemplates(config: PrivateConfigClass) { public loadExtensionTemplates(config: PrivateConfigClass) {
if (!this.extensionsFolder) { if (!ProjectPath.ExtensionFolder) {
throw new Error('Unknown extensions folder.'); throw new Error('Unknown extensions folder.');
} }
// already loaded // already loaded
if (!this.loaded) { if (!this.loaded) {
this.extensionTemplates = []; this.extensionTemplates = [];
if (fs.existsSync(this.extensionsFolder)) { if (fs.existsSync(ProjectPath.ExtensionFolder)) {
this.extensionList = (fs this.extensionList = (fs
.readdirSync(this.extensionsFolder)) .readdirSync(ProjectPath.ExtensionFolder))
.filter((f): boolean => .filter((f): boolean =>
fs.statSync(path.join(this.extensionsFolder, f)).isDirectory() fs.statSync(path.join(ProjectPath.ExtensionFolder, f)).isDirectory()
); );
this.extensionList.sort(); this.extensionList.sort();
for (let i = 0; i < this.extensionList.length; ++i) { for (let i = 0; i < this.extensionList.length; ++i) {
const extFolder = this.extensionList[i]; const extFolder = this.extensionList[i];
const extPath = path.join(this.extensionsFolder, extFolder); const extPath = path.join(ProjectPath.ExtensionFolder, extFolder);
const configExtPath = path.join(extPath, 'config.js'); const configExtPath = path.join(extPath, 'config.js');
const serverExtPath = path.join(extPath, 'server.js'); const serverExtPath = path.join(extPath, 'server.js');

View File

@ -1,8 +1,7 @@
import {ExtensionConfigWrapper} from '../../../backend/model/extension/ExtensionConfigWrapper'; import {ExtensionConfigWrapper} from '../../../backend/model/extension/ExtensionConfigWrapper';
import {PrivateConfigClass} from './PrivateConfigClass'; import {PrivateConfigClass} from './PrivateConfigClass';
import {ConfigClassBuilder} from 'typeconfig/node'; import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigTemplateLoader} from '../../../backend/model/extension/ExtensionConfigTemplateLoader'; import {ProjectPath} from '../../../backend/ProjectPath';
import * as path from 'path';
// we need to know the location of the extensions to load the full config (including the extensions) // we need to know the location of the extensions to load the full config (including the extensions)
const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass()); const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
@ -10,6 +9,9 @@ try {
pre.loadSync({preventSaving: true}); pre.loadSync({preventSaving: true});
} catch (e) { /* empty */ } catch (e) { /* empty */
} }
ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder)); // load extension paths before full config load
ProjectPath.init(pre);
export const Config = ExtensionConfigWrapper.originalSync(true); export const Config = ExtensionConfigWrapper.originalSync(true);
// set actual config
ProjectPath.init(Config);