Skip to content

Commit

Permalink
Merge pull request #768 from bpatrik/feature/extension
Browse files Browse the repository at this point in the history
Add backend extension support #743
  • Loading branch information
bpatrik committed Nov 19, 2023
2 parents 1b26602 + d7ca7cb commit d38830f
Show file tree
Hide file tree
Showing 79 changed files with 1,700 additions and 538 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ locale.source.xlf
test.*
/db/
/test/cypress/screenshots/
/extensions/
6 changes: 3 additions & 3 deletions benchmark/BenchmarkRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class BenchmarkRunner {
const bm = new Benchmark('List directory', req,
async (): Promise<void> => {
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
await ObjectManagers.getInstance().init();
}, null,
async (): Promise<void> => {
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
Expand All @@ -135,7 +135,7 @@ export class BenchmarkRunner {
async bmListPersons(): Promise<BenchmarkResult[]> {
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
await ObjectManagers.getInstance().init();
}, null,
async (): Promise<void> => {
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
Expand Down Expand Up @@ -289,7 +289,7 @@ export class BenchmarkRunner {
await fs.promises.rm(ProjectPath.DBFolder, {recursive: true, force: true});
Config.Database.type = DatabaseType.sqlite;
Config.Jobs.scheduled = [];
await ObjectManagers.InitSQLManagers();
await ObjectManagers.getInstance().init();
};

private async setupDB(): Promise<void> {
Expand Down
21 changes: 14 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"create-release": "gulp create-release",
"build-backend": "tsc",
"pretest": "tsc",
"test": "ng test && nyc mocha --recursive test",
"test-backend": "tsc && mocha --recursive test",
"test": "ng test && nyc mocha --recursive test --exclude test/cypress/**/*.js",
"test-backend": "tsc && mocha --recursive test --exclude test/cypress/**/*.js",
"coverage": "nyc report --reporter=lcov",
"start": "node ./src/backend/index",
"run-dev": "ng build --configuration=dev",
Expand Down Expand Up @@ -113,7 +113,7 @@
"codelyzer": "6.0.2",
"core-js": "3.29.0",
"coveralls": "3.1.1",
"cypress": "latest",
"cypress": "13.1.0",
"deep-equal-in-any-order": "2.0.5",
"ejs-loader": "0.5.0",
"eslint": "8.36.0",
Expand Down
42 changes: 37 additions & 5 deletions src/backend/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,42 @@ const forcedDebug = process.env['NODE_ENV'] === 'debug';

if (forcedDebug === true) {
console.log(
'NODE_ENV environmental variable is set to debug, forcing all logs to print'
'NODE_ENV environmental variable is set to debug, forcing all logs to print'
);
}

export type LoggerFunction = (...args: (string | number)[]) => void;

export interface ILogger {
silly: LoggerFunction;
debug: LoggerFunction;
verbose: LoggerFunction;
info: LoggerFunction;
warn: LoggerFunction;
error: LoggerFunction;
}

export const createLoggerWrapper = (TAG: string): ILogger => ({
silly: (...args: (string | number)[]) => {
Logger.silly(TAG, ...args);
},
debug: (...args: (string | number)[]) => {
Logger.debug(TAG, ...args);
},
verbose: (...args: (string | number)[]) => {
Logger.verbose(TAG, ...args);
},
info: (...args: (string | number)[]) => {
Logger.info(TAG, ...args);
},
warn: (...args: (string | number)[]) => {
Logger.warn(TAG, ...args);
},
error: (...args: (string | number)[]) => {
Logger.error(TAG, ...args);
}
});

export class Logger {
public static silly(...args: (string | number)[]): void {
if (!forcedDebug && Config.Server.Log.level < LogLevel.silly) {
Expand Down Expand Up @@ -55,10 +87,10 @@ export class Logger {
const date = new Date().toLocaleString();
let LOG_TAG = '';
if (
args.length > 0 &&
typeof args[0] === 'string' &&
args[0].startsWith('[') &&
args[0].endsWith(']')
args.length > 0 &&
typeof args[0] === 'string' &&
args[0].startsWith('[') &&
args[0].endsWith(']')
) {
LOG_TAG = args[0];
args.shift();
Expand Down
10 changes: 6 additions & 4 deletions src/backend/ProjectPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import * as path from 'path';
import * as fs from 'fs';
import {Config} from '../common/config/private/Config';

class ProjectPathClass {
export class ProjectPathClass {
public Root: string;
public ImageFolder: string;
public TempFolder: string;
public TranscodedFolder: string;
public FacesFolder: string;
public FrontendFolder: string;
public ExtensionFolder: string;
public DBFolder: string;

constructor() {
this.reset();
}

normalizeRelative(pathStr: string): string {
public normalizeRelative(pathStr: string): string {
return path.join(pathStr, path.sep);
}

getAbsolutePath(pathStr: string): string {
public getAbsolutePath(pathStr: string): string {
return path.isAbsolute(pathStr) ? pathStr : path.join(this.Root, pathStr);
}

getRelativePathToImages(pathStr: string): string {
public getRelativePathToImages(pathStr: string): string {
return path.relative(this.ImageFolder, pathStr);
}

Expand All @@ -35,6 +36,7 @@ class ProjectPathClass {
this.TranscodedFolder = path.join(this.TempFolder, 'tc');
this.FacesFolder = path.join(this.TempFolder, 'f');
this.DBFolder = this.getAbsolutePath(Config.Database.dbFolder);
this.ExtensionFolder = path.join(this.Root, 'extensions');

// create thumbnail folder if not exist
if (!fs.existsSync(this.TempFolder)) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ if ((process.argv || []).includes('--run-diagnostics')) {
process.exit(0);
});
} else {
new Server();
Server.getInstance();
}
3 changes: 2 additions & 1 deletion src/backend/middlewares/RenderingMWs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SharingDTO} from '../../common/entities/SharingDTO';
import {Utils} from '../../common/Utils';
import {LoggerRouter} from '../routes/LoggerRouter';
import {TAGS} from '../../common/config/public/ClientConfig';
import {ExtensionConfigWrapper} from '../model/extension/ExtensionConfigWrapper';

const forcedDebug = process.env['NODE_ENV'] === 'debug';

Expand Down Expand Up @@ -107,7 +108,7 @@ export class RenderingMWs {
req: Request,
res: Response
): Promise<void> {
const originalConf = await Config.original();
const originalConf = await ExtensionConfigWrapper.original();
// These are sensitive information, do not send to the client side
originalConf.Server.sessionSecret = null;
const message = new Message<PrivateConfigClass>(
Expand Down
Loading

0 comments on commit d38830f

Please sign in to comment.