Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for extension config loading (issue #847) #884

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixes for extension config loading (issue #847)
* Actually add/remove extensions from `Config.Extensions.extensions`
* Fix the file path where `ExtensionConfigTemplateLoader` looks for extensions
* Prevent the first `loadSync()` call from creating a `config.json` file
  Works around bpatrik/typeconfig#27
mblythe86 committed Apr 12, 2024
commit b04dc6046abc86a0eca6898fc2961095af9cbc76
9 changes: 9 additions & 0 deletions src/backend/model/extension/ExtensionManager.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import {SQLConnection} from '../database/SQLConnection';
import {ExtensionObject} from './ExtensionObject';
import {ExtensionDecoratorObject} from './ExtensionDecorator';
import * as util from 'util';
import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const exec = util.promisify(require('child_process').exec);

@@ -79,6 +80,14 @@ export class ExtensionManager implements IObjectManager {
);
extList.sort();

// delete not existing extensions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wanted to avoid this. (i.e.: I removed this laoding here on porpuse.)

I would like to have a single place that is responsible loading extension config (even if they do not exists, then its an empty config).
That is why I moved all code to the extension config loader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a closer look at the extension config loader. I didn't see anywhere else that Config.Extensions.extensions.push(new ServerExtensionsEntryConfig(ep))); happened, so the extension configs never actually got loaded into Config.

Config.Extensions.extensions = Config.Extensions.extensions.filter(ec => extList.indexOf(ec.path) !== -1);


// Add new extensions
const ePaths = Config.Extensions.extensions.map(ec => ec.path);
extList.filter(ep => ePaths.indexOf(ep) === -1).forEach(ep =>
Config.Extensions.extensions.push(new ServerExtensionsEntryConfig(ep)));

Logger.debug(LOG_TAG, 'Extensions found: ', JSON.stringify(Config.Extensions.extensions.map(ec => ec.path)));
}
6 changes: 5 additions & 1 deletion src/common/config/private/Config.ts
Original file line number Diff line number Diff line change
@@ -6,8 +6,12 @@ import * as path from 'path';

const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
try {
//NOTE: can possibly remove this saveIfNotExist hack if typeconfig issue #27 is fixed
const origSaveIfNotExist = (pre.__options as any).saveIfNotExist;
mblythe86 marked this conversation as resolved.
Show resolved Hide resolved
(pre.__options as any).saveIfNotExist = false;
pre.loadSync();
(pre.__options as any).saveIfNotExist = origSaveIfNotExist;
} catch (e) { /* empty */ }
ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder));
ExtensionConfigTemplateLoader.Instance.init(pre.Extensions.folder);

export const Config = ExtensionConfigWrapper.originalSync(true);

Unchanged files with check annotations Beta

);
}
export type LoggerArgs = (string | number | (() => string) | Record<any, unknown> | Error);

Check warning on line 14 in src/backend/Logger.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
export type LoggerFunction = (...args: LoggerArgs[]) => void;
export interface ILogger {
import {TAGS} from '../../../common/config/public/ClientConfig';
import {ObjectManagers} from '../../model/ObjectManagers';
import {ExtensionConfigWrapper} from '../../model/extension/ExtensionConfigWrapper';
import {Logger} from '../../Logger';

Check warning on line 9 in src/backend/middlewares/admin/SettingsMWs.ts

GitHub Actions / test (18.x)

'Logger' is defined but never used
const LOG_TAG = '[SettingsMWs]';

Check warning on line 11 in src/backend/middlewares/admin/SettingsMWs.ts

GitHub Actions / test (18.x)

'LOG_TAG' is assigned a value but never used
export class SettingsMWs {
AuthenticationMWs.authorise(minRole)] : [];
}
public jsonResponse(paths: string[], minRole: UserRoles, cb: (params?: ParamsDictionary, body?: any, user?: UserDTO) => Promise<unknown> | unknown) {

Check warning on line 55 in src/backend/model/extension/ExpressRouterWrapper.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
const fullPaths = paths.map(p => (Utils.concatUrls('/' + this.name + '/' + p)));
this.router[this.func](fullPaths,
...(this.getAuthMWs(minRole).concat([
import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig';
const LOG_TAG = '[ExtensionConfigTemplateLoader]';

Check warning on line 7 in src/backend/model/extension/ExtensionConfigTemplateLoader.ts

GitHub Actions / test (18.x)

'LOG_TAG' is assigned a value but never used
/**
* This class decouples the extension management and the config.
* @param cb function callback
* @return newly added REST api path
*/
jsonResponse(paths: string[], minRole: UserRoles, cb: (params?: ParamsDictionary, body?: any, user?: UserDTO) => Promise<unknown> | unknown): string;

Check warning on line 102 in src/backend/model/extension/IExtension.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
/**
* Exposes a standard expressjs middleware
for (const sidecarPath of sidecarPaths) {
if (fs.existsSync(sidecarPath)) {
const sidecarData: any = await exifr.sidecar(sidecarPath);

Check warning on line 144 in src/backend/model/fileaccess/MetadataLoader.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
if (sidecarData !== undefined) {
MetadataLoader.mapMetadata(metadata, sidecarData);
}
for (const sidecarPath of sidecarPaths) {
if (fs.existsSync(sidecarPath)) {
const sidecarData: any = await exifr.sidecar(sidecarPath, exifrOptions);

Check warning on line 249 in src/backend/model/fileaccess/MetadataLoader.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
if (sidecarData !== undefined) {
MetadataLoader.mapMetadata(metadata, sidecarData);
}
return metadata;
}
private static mapMetadata(metadata: PhotoMetadata, exif: any) {

Check warning on line 276 in src/backend/model/fileaccess/MetadataLoader.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
//replace adobe xap-section with xmp to reuse parsing
if (Object.hasOwn(exif, 'xap')) {
exif['xmp'] = exif['xap'];
}
}
private static getOrientation(exif: any): number {

Check warning on line 297 in src/backend/model/fileaccess/MetadataLoader.ts

GitHub Actions / test (18.x)

Unexpected any. Specify a different type
let orientation = 1; //Orientation 1 is normal
if (exif.ifd0?.Orientation != undefined) {
orientation = parseInt(exif.ifd0.Orientation as any, 10) as number;