Skip to content

Commit d38830f

Browse files
authored
Merge pull request #768 from bpatrik/feature/extension
Add backend extension support #743
2 parents 1b26602 + d7ca7cb commit d38830f

File tree

79 files changed

+1700
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1700
-538
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ locale.source.xlf
2828
test.*
2929
/db/
3030
/test/cypress/screenshots/
31+
/extensions/

benchmark/BenchmarkRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class BenchmarkRunner {
121121
const bm = new Benchmark('List directory', req,
122122
async (): Promise<void> => {
123123
await ObjectManagers.reset();
124-
await ObjectManagers.InitSQLManagers();
124+
await ObjectManagers.getInstance().init();
125125
}, null,
126126
async (): Promise<void> => {
127127
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
@@ -135,7 +135,7 @@ export class BenchmarkRunner {
135135
async bmListPersons(): Promise<BenchmarkResult[]> {
136136
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
137137
await ObjectManagers.reset();
138-
await ObjectManagers.InitSQLManagers();
138+
await ObjectManagers.getInstance().init();
139139
}, null,
140140
async (): Promise<void> => {
141141
Config.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
@@ -289,7 +289,7 @@ export class BenchmarkRunner {
289289
await fs.promises.rm(ProjectPath.DBFolder, {recursive: true, force: true});
290290
Config.Database.type = DatabaseType.sqlite;
291291
Config.Jobs.scheduled = [];
292-
await ObjectManagers.InitSQLManagers();
292+
await ObjectManagers.getInstance().init();
293293
};
294294

295295
private async setupDB(): Promise<void> {

package-lock.json

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"create-release": "gulp create-release",
1414
"build-backend": "tsc",
1515
"pretest": "tsc",
16-
"test": "ng test && nyc mocha --recursive test",
17-
"test-backend": "tsc && mocha --recursive test",
16+
"test": "ng test && nyc mocha --recursive test --exclude test/cypress/**/*.js",
17+
"test-backend": "tsc && mocha --recursive test --exclude test/cypress/**/*.js",
1818
"coverage": "nyc report --reporter=lcov",
1919
"start": "node ./src/backend/index",
2020
"run-dev": "ng build --configuration=dev",
@@ -113,7 +113,7 @@
113113
"codelyzer": "6.0.2",
114114
"core-js": "3.29.0",
115115
"coveralls": "3.1.1",
116-
"cypress": "latest",
116+
"cypress": "13.1.0",
117117
"deep-equal-in-any-order": "2.0.5",
118118
"ejs-loader": "0.5.0",
119119
"eslint": "8.36.0",

src/backend/Logger.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,42 @@ const forcedDebug = process.env['NODE_ENV'] === 'debug';
77

88
if (forcedDebug === true) {
99
console.log(
10-
'NODE_ENV environmental variable is set to debug, forcing all logs to print'
10+
'NODE_ENV environmental variable is set to debug, forcing all logs to print'
1111
);
1212
}
1313

14+
export type LoggerFunction = (...args: (string | number)[]) => void;
15+
16+
export interface ILogger {
17+
silly: LoggerFunction;
18+
debug: LoggerFunction;
19+
verbose: LoggerFunction;
20+
info: LoggerFunction;
21+
warn: LoggerFunction;
22+
error: LoggerFunction;
23+
}
24+
25+
export const createLoggerWrapper = (TAG: string): ILogger => ({
26+
silly: (...args: (string | number)[]) => {
27+
Logger.silly(TAG, ...args);
28+
},
29+
debug: (...args: (string | number)[]) => {
30+
Logger.debug(TAG, ...args);
31+
},
32+
verbose: (...args: (string | number)[]) => {
33+
Logger.verbose(TAG, ...args);
34+
},
35+
info: (...args: (string | number)[]) => {
36+
Logger.info(TAG, ...args);
37+
},
38+
warn: (...args: (string | number)[]) => {
39+
Logger.warn(TAG, ...args);
40+
},
41+
error: (...args: (string | number)[]) => {
42+
Logger.error(TAG, ...args);
43+
}
44+
});
45+
1446
export class Logger {
1547
public static silly(...args: (string | number)[]): void {
1648
if (!forcedDebug && Config.Server.Log.level < LogLevel.silly) {
@@ -55,10 +87,10 @@ export class Logger {
5587
const date = new Date().toLocaleString();
5688
let LOG_TAG = '';
5789
if (
58-
args.length > 0 &&
59-
typeof args[0] === 'string' &&
60-
args[0].startsWith('[') &&
61-
args[0].endsWith(']')
90+
args.length > 0 &&
91+
typeof args[0] === 'string' &&
92+
args[0].startsWith('[') &&
93+
args[0].endsWith(']')
6294
) {
6395
LOG_TAG = args[0];
6496
args.shift();

src/backend/ProjectPath.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@ import * as path from 'path';
22
import * as fs from 'fs';
33
import {Config} from '../common/config/private/Config';
44

5-
class ProjectPathClass {
5+
export class ProjectPathClass {
66
public Root: string;
77
public ImageFolder: string;
88
public TempFolder: string;
99
public TranscodedFolder: string;
1010
public FacesFolder: string;
1111
public FrontendFolder: string;
12+
public ExtensionFolder: string;
1213
public DBFolder: string;
1314

1415
constructor() {
1516
this.reset();
1617
}
1718

18-
normalizeRelative(pathStr: string): string {
19+
public normalizeRelative(pathStr: string): string {
1920
return path.join(pathStr, path.sep);
2021
}
2122

22-
getAbsolutePath(pathStr: string): string {
23+
public getAbsolutePath(pathStr: string): string {
2324
return path.isAbsolute(pathStr) ? pathStr : path.join(this.Root, pathStr);
2425
}
2526

26-
getRelativePathToImages(pathStr: string): string {
27+
public getRelativePathToImages(pathStr: string): string {
2728
return path.relative(this.ImageFolder, pathStr);
2829
}
2930

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

3941
// create thumbnail folder if not exist
4042
if (!fs.existsSync(this.TempFolder)) {

src/backend/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ if ((process.argv || []).includes('--run-diagnostics')) {
1111
process.exit(0);
1212
});
1313
} else {
14-
new Server();
14+
Server.getInstance();
1515
}

src/backend/middlewares/RenderingMWs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {SharingDTO} from '../../common/entities/SharingDTO';
99
import {Utils} from '../../common/Utils';
1010
import {LoggerRouter} from '../routes/LoggerRouter';
1111
import {TAGS} from '../../common/config/public/ClientConfig';
12+
import {ExtensionConfigWrapper} from '../model/extension/ExtensionConfigWrapper';
1213

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

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

0 commit comments

Comments
 (0)