1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/routes/GalleryRouter.ts

137 lines
4.2 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs';
import {Express, NextFunction, Request, Response} from 'express';
2018-03-31 03:30:30 +08:00
import {GalleryMWs} from '../middlewares/GalleryMWs';
import {RenderingMWs} from '../middlewares/RenderingMWs';
import {ThumbnailGeneratorMWs} from '../middlewares/thumbnail/ThumbnailGeneratorMWs';
import {UserRoles} from '../../common/entities/UserDTO';
2018-11-05 02:28:32 +08:00
import {ThumbnailSourceType} from '../model/threading/ThumbnailWorker';
2016-05-09 23:04:56 +08:00
export class GalleryRouter {
2018-11-29 06:49:33 +08:00
public static route(app: Express) {
this.addGetImageIcon(app);
this.addGetImageThumbnail(app);
2018-11-05 02:28:32 +08:00
this.addGetVideoThumbnail(app);
this.addGetImage(app);
2018-11-05 02:28:32 +08:00
this.addGetVideo(app);
2018-11-26 07:26:29 +08:00
this.addGetMetaFile(app);
this.addRandom(app);
this.addDirectoryList(app);
this.addSearch(app);
this.addInstantSearch(app);
this.addAutoComplete(app);
}
2018-11-29 06:49:33 +08:00
private static addDirectoryList(app: Express) {
2018-03-31 03:30:30 +08:00
app.get(['/api/gallery/content/:directory(*)', '/api/gallery/', '/api/gallery//'],
AuthenticationMWs.authenticate,
2017-07-04 01:17:49 +08:00
AuthenticationMWs.authoriseDirectory,
GalleryMWs.listDirectory,
ThumbnailGeneratorMWs.addThumbnailInformation,
2018-11-19 03:26:29 +08:00
GalleryMWs.cleanUpGalleryResults,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addGetImage(app: Express) {
2019-01-13 01:08:34 +08:00
app.get(['/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))'],
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
2018-11-05 02:28:32 +08:00
RenderingMWs.renderFile
);
}
2018-11-29 06:49:33 +08:00
private static addGetVideo(app: Express) {
2018-12-02 06:53:58 +08:00
app.get(['/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))'],
2018-11-05 02:28:32 +08:00
AuthenticationMWs.authenticate,
// TODO: authorize path
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
2018-11-29 06:49:33 +08:00
private static addGetMetaFile(app: Express) {
2018-12-02 06:53:58 +08:00
app.get(['/api/gallery/content/:mediaPath(*\.(gpx))'],
2018-11-26 07:26:29 +08:00
AuthenticationMWs.authenticate,
// TODO: authorize path
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addRandom(app: Express) {
app.get(['/api/gallery/random'],
AuthenticationMWs.authenticate,
// TODO: authorize path
GalleryMWs.getRandomImage,
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
2018-11-29 06:49:33 +08:00
private static addGetImageThumbnail(app: Express) {
2019-01-13 01:08:34 +08:00
app.get('/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))/thumbnail/:size?',
2018-11-05 02:28:32 +08:00
AuthenticationMWs.authenticate,
// TODO: authorize path
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
2018-11-05 02:28:32 +08:00
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Image),
RenderingMWs.renderFile
);
}
2018-11-29 06:49:33 +08:00
private static addGetVideoThumbnail(app: Express) {
2018-12-02 06:53:58 +08:00
app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?',
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
2018-11-05 02:28:32 +08:00
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Video),
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addGetImageIcon(app: Express) {
2019-01-13 01:08:34 +08:00
app.get('/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))/icon',
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
2018-11-26 07:26:29 +08:00
GalleryMWs.loadFile,
2018-11-05 02:28:32 +08:00
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Image),
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addSearch(app: Express) {
2018-03-31 03:30:30 +08:00
app.get('/api/search/:text',
AuthenticationMWs.authenticate,
2017-07-09 18:03:17 +08:00
AuthenticationMWs.authorise(UserRoles.Guest),
GalleryMWs.search,
ThumbnailGeneratorMWs.addThumbnailInformation,
2018-11-19 03:26:29 +08:00
GalleryMWs.cleanUpGalleryResults,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addInstantSearch(app: Express) {
2018-03-31 03:30:30 +08:00
app.get('/api/instant-search/:text',
AuthenticationMWs.authenticate,
2017-07-09 18:03:17 +08:00
AuthenticationMWs.authorise(UserRoles.Guest),
GalleryMWs.instantSearch,
ThumbnailGeneratorMWs.addThumbnailInformation,
2018-11-19 03:26:29 +08:00
GalleryMWs.cleanUpGalleryResults,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
2018-11-29 06:49:33 +08:00
private static addAutoComplete(app: Express) {
2018-03-31 03:30:30 +08:00
app.get('/api/autocomplete/:text',
AuthenticationMWs.authenticate,
2017-07-09 18:03:17 +08:00
AuthenticationMWs.authorise(UserRoles.Guest),
GalleryMWs.autocomplete,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
}