2018-03-30 15:30:30 -04:00
|
|
|
import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs';
|
|
|
|
import {GalleryMWs} from '../middlewares/GalleryMWs';
|
|
|
|
import {RenderingMWs} from '../middlewares/RenderingMWs';
|
|
|
|
import {ThumbnailGeneratorMWs} from '../middlewares/thumbnail/ThumbnailGeneratorMWs';
|
|
|
|
import {UserRoles} from '../../common/entities/UserDTO';
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
export class GalleryRouter {
|
2017-06-10 22:32:56 +02:00
|
|
|
public static route(app: any) {
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
this.addGetImageIcon(app);
|
|
|
|
this.addGetImageThumbnail(app);
|
|
|
|
this.addGetImage(app);
|
|
|
|
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
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
private static addDirectoryList(app) {
|
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,
|
2017-07-03 19:17:49 +02:00
|
|
|
AuthenticationMWs.authoriseDirectory,
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.listDirectory,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
|
|
|
GalleryMWs.removeCyclicDirectoryReferences,
|
|
|
|
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
|
|
|
private static addGetImage(app) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get(['/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))'],
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-30 15:30:30 -04:00
|
|
|
// TODO: authorize path
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.loadImage,
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
private static addGetImageThumbnail(app) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get('/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-30 15:30:30 -04:00
|
|
|
// TODO: authorize path
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.loadImage,
|
|
|
|
ThumbnailGeneratorMWs.generateThumbnail,
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
private static addGetImageIcon(app) {
|
2018-03-30 15:30:30 -04:00
|
|
|
app.get('/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))/icon',
|
2017-06-10 22:32:56 +02:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-30 15:30:30 -04:00
|
|
|
// TODO: authorize path
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.loadImage,
|
|
|
|
ThumbnailGeneratorMWs.generateIcon,
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2017-01-22 22:31:29 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
private static addSearch(app) {
|
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),
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.search,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
|
|
|
GalleryMWs.removeCyclicDirectoryReferences,
|
|
|
|
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
|
|
|
private static addInstantSearch(app) {
|
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),
|
2017-06-10 22:32:56 +02:00
|
|
|
GalleryMWs.instantSearch,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
|
|
|
GalleryMWs.removeCyclicDirectoryReferences,
|
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-30 15:30:30 -04:00
|
|
|
}
|
2016-05-09 19:14:33 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
private static addAutoComplete(app) {
|
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),
|
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
|
|
|
}
|