• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bpatrik / pigallery2 / 17778692742

16 Sep 2025 08:51PM UTC coverage: 66.26% (-0.3%) from 66.537%
17778692742

push

github

bpatrik
Implement reloading mechanics #1032

1332 of 2254 branches covered (59.09%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 2 files covered. (25.0%)

155 existing lines in 6 files now uncovered.

4858 of 7088 relevant lines covered (68.54%)

4314.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.86
/src/backend/model/extension/ExpressRouterWrapper.ts
1
import * as express from 'express';
2
import {NextFunction, Request, Response} from 'express';
3
import {UserDTO, UserRoles} from '../../../common/entities/UserDTO';
4
import {AuthenticationMWs} from '../../middlewares/user/AuthenticationMWs';
1✔
5
import {RenderingMWs} from '../../middlewares/RenderingMWs';
1✔
6
import {ParamsDictionary} from 'express-serve-static-core';
7
import {IExtensionRESTApi, IExtensionRESTRoute} from './IExtension';
8
import {ILogger} from '../../Logger';
9
import {ExtensionManager} from './ExtensionManager';
1✔
10
import {Utils} from '../../../common/Utils';
1✔
11
import {GalleryMWs} from '../../middlewares/GalleryMWs';
1✔
12
import {MediaEntity} from '../database/enitites/MediaEntity';
1✔
13
import {SQLConnection} from '../database/SQLConnection';
1✔
14
import {Repository} from 'typeorm';
15
import {ObjectManagers} from '../ObjectManagers';
1✔
16

17

18
export class ExpressRouterWrapper implements IExtensionRESTApi {
1✔
19

UNCOV
20
  constructor(private readonly router: express.Router,
×
UNCOV
21
              private readonly name: string,
×
22
              private readonly extLogger: ILogger) {
×
23
  }
24

25
  get use() {
26
    return new ExpressRouteWrapper(this.router, this.name, 'use', this.extLogger);
×
27
  }
28

29
  get get() {
30
    return new ExpressRouteWrapper(this.router, this.name, 'get', this.extLogger);
×
31
  }
32

33
  get put() {
34
    return new ExpressRouteWrapper(this.router, this.name, 'put', this.extLogger);
×
35
  }
36

37
  get post() {
38
    return new ExpressRouteWrapper(this.router, this.name, 'post', this.extLogger);
×
39
  }
40

41
  get delete() {
UNCOV
42
    return new ExpressRouteWrapper(this.router, this.name, 'delete', this.extLogger);
×
43
  }
44

45
}
46

47
export class ExpressRouteWrapper implements IExtensionRESTRoute {
1✔
48

UNCOV
49
  constructor(private readonly router: express.Router,
×
UNCOV
50
              private readonly name: string,
×
UNCOV
51
              private readonly func: 'get' | 'use' | 'put' | 'post' | 'delete',
×
52
              private readonly extLogger: ILogger) {
×
53
  }
54

55
  public mediaJsonResponse(paths: string[], minRole: UserRoles, invalidateDirectory: boolean, cb: (params: ParamsDictionary, body: any, user: UserDTO, media: MediaEntity, repository: Repository<MediaEntity>) => Promise<unknown> | unknown): string {
UNCOV
56
    const fullPaths = paths.map(p => (Utils.concatUrls('/' + this.name + '/' + p)));
×
57
    this.router[this.func](fullPaths,
×
58
      ...(this.getAuthMWs(minRole).concat([
59
        async (req: Request, res: Response, next: NextFunction) => {
UNCOV
60
          req.params['mediaPath'] = req.body.media;
×
61
          next();
×
62
        },
63
        AuthenticationMWs.normalizePathParam('mediaPath'),
64
        AuthenticationMWs.authoriseMedia('mediaPath'),
65
        GalleryMWs.getMediaEntry,
66
        async (req: Request, res: Response, next: NextFunction) => {
67
          try {
×
68
            const media = req.resultPipe as MediaEntity;
×
UNCOV
69
            const connection = await SQLConnection.getConnection();
×
UNCOV
70
            await cb(req.params,
×
71
              req.body,
72
              req.session.context.user,
73
              media,
74
              connection.getRepository(MediaEntity));
NEW
75
            if (invalidateDirectory) {
×
NEW
76
              await ObjectManagers.getInstance().onDataChange(media.directory);
×
77
            }
78
            req.resultPipe = 'ok';
×
79
            next();
×
80
          } catch (e) {
81
            next(new Error(`[${this.name}]Error during processing:${paths}`));
×
82
          }
83
        },
84
        RenderingMWs.renderResult
85
      ])));
UNCOV
86
    const p = ExtensionManager.EXTENSION_API_PATH + fullPaths;
×
UNCOV
87
    this.extLogger.silly(`Listening on ${this.func} ${p}`);
×
UNCOV
88
    return p;
×
89
  }
90

91
  public jsonResponse(paths: string[], minRole: UserRoles, cb: (params?: ParamsDictionary, body?: any, user?: UserDTO) => Promise<unknown> | unknown): string {
UNCOV
92
    const fullPaths = paths.map(p => (Utils.concatUrls('/' + this.name + '/' + p)));
×
UNCOV
93
    this.router[this.func](fullPaths,
×
94
      ...(this.getAuthMWs(minRole).concat([
95
        async (req: Request, res: Response, next: NextFunction) => {
UNCOV
96
          try {
×
UNCOV
97
            req.resultPipe = await cb(req.params, req.body, req.session.context.user);
×
UNCOV
98
            next();
×
99
          } catch (e) {
UNCOV
100
            next(new Error(`[${this.name}]Error during processing:${paths}`));
×
101
          }
102
        },
103
        RenderingMWs.renderResult
104
      ])));
UNCOV
105
    const p = ExtensionManager.EXTENSION_API_PATH + fullPaths;
×
UNCOV
106
    this.extLogger.silly(`Listening on ${this.func} ${p}`);
×
UNCOV
107
    return p;
×
108
  }
109

110
  public rawMiddleware(paths: string[], minRole: UserRoles, mw: (req: Request, res: Response, next: NextFunction) => void | Promise<void>): string {
UNCOV
111
    const fullPaths = paths.map(p => (Utils.concatUrls('/' + this.name + '/' + p)));
×
UNCOV
112
    this.router[this.func](fullPaths,
×
113
      ...this.getAuthMWs(minRole),
114
      mw);
UNCOV
115
    const p = ExtensionManager.EXTENSION_API_PATH + fullPaths;
×
UNCOV
116
    this.extLogger.silly(`Listening on ${this.func} ${p}`);
×
UNCOV
117
    return p;
×
118
  }
119

120
  private getAuthMWs(minRole: UserRoles) {
UNCOV
121
    return minRole ? [AuthenticationMWs.authenticate,
×
122
      AuthenticationMWs.authorise(minRole)] : [];
123
  }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc