1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08: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 fs from 'fs';
import {Config} from '../common/config/private/Config';
import {PrivateConfigClass} from '../common/config/private/PrivateConfigClass';
export class ProjectPathClass {
public Root: string;
@ -11,8 +11,10 @@ export class ProjectPathClass {
public FrontendFolder: string;
public ExtensionFolder: string;
public DBFolder: string;
private cfg: PrivateConfigClass;
constructor() {
init(cfg: PrivateConfigClass) {
this.cfg = cfg;
this.reset();
}
@ -31,12 +33,12 @@ export class ProjectPathClass {
reset(): void {
this.Root = path.join(__dirname, '/../../');
this.FrontendFolder = path.join(this.Root, 'dist');
this.ImageFolder = this.getAbsolutePath(Config.Media.folder);
this.TempFolder = this.getAbsolutePath(Config.Media.tempFolder);
this.ImageFolder = this.getAbsolutePath(this.cfg.Media.folder);
this.TempFolder = this.getAbsolutePath(this.cfg.Media.tempFolder);
this.TranscodedFolder = path.join(this.TempFolder, 'tc');
this.FacesFolder = path.join(this.TempFolder, 'f');
this.DBFolder = this.getAbsolutePath(Config.Database.dbFolder);
this.ExtensionFolder = this.getAbsolutePath(Config.Extensions.folder);
this.DBFolder = this.getAbsolutePath(this.cfg.Database.dbFolder);
this.ExtensionFolder = this.getAbsolutePath(this.cfg.Extensions.folder);
// create thumbnail folder if not exist
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 path from 'path';
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.
@ -16,7 +13,6 @@ const LOG_TAG = '[ExtensionConfigTemplateLoader]';
export class ExtensionConfigTemplateLoader {
private static instance: ExtensionConfigTemplateLoader;
private extensionsFolder: string;
private loaded = false;
private extensionList: string[] = [];
@ -31,29 +27,26 @@ export class ExtensionConfigTemplateLoader {
}
init(extensionsFolder: string) {
this.extensionsFolder = extensionsFolder;
}
public loadExtensionTemplates(config: PrivateConfigClass) {
if (!this.extensionsFolder) {
if (!ProjectPath.ExtensionFolder) {
throw new Error('Unknown extensions folder.');
}
// already loaded
if (!this.loaded) {
this.extensionTemplates = [];
if (fs.existsSync(this.extensionsFolder)) {
if (fs.existsSync(ProjectPath.ExtensionFolder)) {
this.extensionList = (fs
.readdirSync(this.extensionsFolder))
.readdirSync(ProjectPath.ExtensionFolder))
.filter((f): boolean =>
fs.statSync(path.join(this.extensionsFolder, f)).isDirectory()
fs.statSync(path.join(ProjectPath.ExtensionFolder, 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 extPath = path.join(ProjectPath.ExtensionFolder, extFolder);
const configExtPath = path.join(extPath, 'config.js');
const serverExtPath = path.join(extPath, 'server.js');

View File

@ -1,8 +1,7 @@
import {ExtensionConfigWrapper} from '../../../backend/model/extension/ExtensionConfigWrapper';
import {PrivateConfigClass} from './PrivateConfigClass';
import {ConfigClassBuilder} from 'typeconfig/node';
import {ExtensionConfigTemplateLoader} from '../../../backend/model/extension/ExtensionConfigTemplateLoader';
import * as path from 'path';
import {ProjectPath} from '../../../backend/ProjectPath';
// we need to know the location of the extensions to load the full config (including the extensions)
const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
@ -10,6 +9,9 @@ try {
pre.loadSync({preventSaving: true});
} 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);
// set actual config
ProjectPath.init(Config);