1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/routes/PersonRouter.ts
2019-03-10 20:57:27 +01:00

63 lines
1.8 KiB
TypeScript

import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs';
import {Express} from 'express';
import {RenderingMWs} from '../middlewares/RenderingMWs';
import {UserRoles} from '../../common/entities/UserDTO';
import {PersonMWs} from '../middlewares/PersonMWs';
import {ThumbnailGeneratorMWs} from '../middlewares/thumbnail/ThumbnailGeneratorMWs';
import {VersionMWs} from '../middlewares/VersionMWs';
import {Config} from '../../common/config/private/Config';
export class PersonRouter {
public static route(app: Express) {
this.updatePerson(app);
this.addGetPersons(app);
this.getPersonThumbnail(app);
}
private static updatePerson(app: Express) {
app.post(['/api/person/:name'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(Config.Client.Faces.writeAccessMinRole),
VersionMWs.injectGalleryVersion,
// specific part
PersonMWs.updatePerson,
RenderingMWs.renderResult
);
}
private static addGetPersons(app: Express) {
app.get(['/api/person'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.User),
VersionMWs.injectGalleryVersion,
// specific part
PersonMWs.listPersons,
PersonMWs.addSamplePhotoForAll,
ThumbnailGeneratorMWs.addThumbnailInfoForPersons,
PersonMWs.removeSamplePhotoForAll,
RenderingMWs.renderResult
);
}
private static getPersonThumbnail(app: Express) {
app.get(['/api/person/:name/thumbnail'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.User),
VersionMWs.injectGalleryVersion,
// specific part
PersonMWs.getSamplePhoto,
ThumbnailGeneratorMWs.generatePersonThumbnail,
RenderingMWs.renderFile
);
}
}