2018-03-30 15:30:30 -04:00
|
|
|
import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs';
|
2019-02-22 23:39:01 +01:00
|
|
|
import {Express} from 'express';
|
2018-03-30 15:30:30 -04: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-04 19:28:32 +01:00
|
|
|
import {ThumbnailSourceType} from '../model/threading/ThumbnailWorker';
|
2019-02-15 11:47:09 -05:00
|
|
|
import {VersionMWs} from '../middlewares/VersionMWs';
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
export class GalleryRouter {
|
2018-11-28 23:49:33 +01:00
|
|
|
public static route(app: Express) {
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addGetImageIcon(app);
|
2019-01-18 00:26:20 +01:00
|
|
|
this.addGetVideoIcon(app);
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addGetImageThumbnail(app);
|
2018-11-04 19:28:32 +01:00
|
|
|
this.addGetVideoThumbnail(app);
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addGetImage(app);
|
2018-11-04 19:28:32 +01:00
|
|
|
this.addGetVideo(app);
|
2018-11-26 00:26:29 +01:00
|
|
|
this.addGetMetaFile(app);
|
2018-10-22 00:24:17 +02:00
|
|
|
this.addRandom(app);
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addDirectoryList(app);
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addSearch(app);
|
|
|
|
this.addInstantSearch(app);
|
|
|
|
this.addAutoComplete(app);
|
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addDirectoryList(app: Express) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get(['/api/gallery/content/:directory(*)', '/api/gallery/', '/api/gallery//'],
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('directory'),
|
|
|
|
AuthenticationMWs.authorisePath('directory', true),
|
2019-02-15 11:47:09 -05:00
|
|
|
VersionMWs.injectGalleryVersion,
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.listDirectory,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-18 20:26:29 +01:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetImage(app: Express) {
|
2019-01-12 18:08:34 +01:00
|
|
|
app.get(['/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))'],
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2018-11-04 19:28:32 +01:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetVideo(app: Express) {
|
2018-12-01 23:53:58 +01:00
|
|
|
app.get(['/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))'],
|
2018-11-04 19:28:32 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetMetaFile(app: Express) {
|
2018-12-01 23:53:58 +01:00
|
|
|
app.get(['/api/gallery/content/:mediaPath(*\.(gpx))'],
|
2018-11-26 00:26:29 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addRandom(app: Express) {
|
2018-10-22 00:24:17 +02:00
|
|
|
app.get(['/api/gallery/random'],
|
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2019-02-15 11:47:09 -05:00
|
|
|
VersionMWs.injectGalleryVersion,
|
2018-10-22 00:24:17 +02:00
|
|
|
GalleryMWs.getRandomImage,
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2018-10-22 00:24:17 +02:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetImageThumbnail(app: Express) {
|
2019-01-12 18:08:34 +01:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))/thumbnail/:size?',
|
2018-11-04 19:28:32 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2018-11-04 19:28:32 +01:00
|
|
|
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Image),
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetVideoThumbnail(app: Express) {
|
2018-12-01 23:53:58 +01:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2018-11-04 19:28:32 +01:00
|
|
|
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Video),
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2019-01-18 00:26:20 +01:00
|
|
|
|
|
|
|
private static addGetVideoIcon(app: Express) {
|
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/icon',
|
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2019-01-18 00:26:20 +01:00
|
|
|
GalleryMWs.loadFile,
|
|
|
|
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Video),
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addGetImageIcon(app: Express) {
|
2019-01-12 18:08:34 +01:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(jpg|jpeg|jpe|webp|png|gif|svg))/icon',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2019-02-22 23:39:01 +01:00
|
|
|
AuthenticationMWs.normalizePathParam('mediaPath'),
|
|
|
|
AuthenticationMWs.authorisePath('mediaPath', false),
|
2018-11-26 00:26:29 +01:00
|
|
|
GalleryMWs.loadFile,
|
2018-11-04 19:28:32 +01:00
|
|
|
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Image),
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2017-01-22 22:31:29 +01:00
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addSearch(app: Express) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get('/api/search/:text',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 12:03:17 +02:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2019-02-15 11:47:09 -05:00
|
|
|
VersionMWs.injectGalleryVersion,
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.search,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-18 20:26:29 +01:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addInstantSearch(app: Express) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get('/api/instant-search/:text',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 12:03:17 +02:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2019-02-15 11:47:09 -05:00
|
|
|
VersionMWs.injectGalleryVersion,
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.instantSearch,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-18 20:26:29 +01:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-10 22:32:56 +02:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-05-09 19:14:33 +02:00
|
|
|
|
2018-11-28 23:49:33 +01:00
|
|
|
private static addAutoComplete(app: Express) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get('/api/autocomplete/:text',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 12:03:17 +02:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2019-02-15 11:47:09 -05:00
|
|
|
VersionMWs.injectGalleryVersion,
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.autocomplete,
|
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|