2018-03-31 03:30:30 +08: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';
|
2018-11-05 02:28:32 +08:00
|
|
|
import {ThumbnailSourceType} from '../model/threading/ThumbnailWorker';
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
export class GalleryRouter {
|
2017-06-11 04:32:56 +08:00
|
|
|
public static route(app: any) {
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
this.addGetImageIcon(app);
|
|
|
|
this.addGetImageThumbnail(app);
|
2018-11-05 02:28:32 +08:00
|
|
|
this.addGetVideoThumbnail(app);
|
2017-06-11 04:32:56 +08:00
|
|
|
this.addGetImage(app);
|
2018-11-05 02:28:32 +08:00
|
|
|
this.addGetVideo(app);
|
2018-10-22 06:24:17 +08:00
|
|
|
this.addRandom(app);
|
2017-06-11 04:32:56 +08:00
|
|
|
this.addDirectoryList(app);
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
this.addSearch(app);
|
|
|
|
this.addInstantSearch(app);
|
|
|
|
this.addAutoComplete(app);
|
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addDirectoryList(app) {
|
2018-03-31 03:30:30 +08:00
|
|
|
app.get(['/api/gallery/content/:directory(*)', '/api/gallery/', '/api/gallery//'],
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-04 01:17:49 +08:00
|
|
|
AuthenticationMWs.authoriseDirectory,
|
2017-06-11 04:32:56 +08:00
|
|
|
GalleryMWs.listDirectory,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-19 03:26:29 +08:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addGetImage(app) {
|
2018-11-05 02:28:32 +08:00
|
|
|
app.get(['/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))'],
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-31 03:30:30 +08:00
|
|
|
// TODO: authorize path
|
2018-11-05 02:28:32 +08:00
|
|
|
GalleryMWs.loadMedia,
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static addGetVideo(app) {
|
2018-11-25 22:22:07 +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
|
|
|
|
GalleryMWs.loadMedia,
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2018-10-22 06:24:17 +08:00
|
|
|
private static addRandom(app) {
|
|
|
|
app.get(['/api/gallery/random'],
|
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
|
|
|
// TODO: authorize path
|
|
|
|
GalleryMWs.getRandomImage,
|
2018-11-05 02:28:32 +08:00
|
|
|
GalleryMWs.loadMedia,
|
2018-10-22 06:24:17 +08:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addGetImageThumbnail(app) {
|
2018-11-05 02:28:32 +08:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?',
|
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
// TODO: authorize path
|
|
|
|
GalleryMWs.loadMedia,
|
|
|
|
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Image),
|
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static addGetVideoThumbnail(app) {
|
2018-11-25 22:22:07 +08:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?',
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-31 03:30:30 +08:00
|
|
|
// TODO: authorize path
|
2018-11-05 02:28:32 +08:00
|
|
|
GalleryMWs.loadMedia,
|
|
|
|
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Video),
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addGetImageIcon(app) {
|
2018-11-05 02:28:32 +08:00
|
|
|
app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/icon',
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2018-03-31 03:30:30 +08:00
|
|
|
// TODO: authorize path
|
2018-11-05 02:28:32 +08:00
|
|
|
GalleryMWs.loadMedia,
|
|
|
|
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Image),
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderFile
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2017-01-23 05:31:29 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addSearch(app) {
|
2018-03-31 03:30:30 +08:00
|
|
|
app.get('/api/search/:text',
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 18:03:17 +08:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2017-06-11 04:32:56 +08:00
|
|
|
GalleryMWs.search,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-19 03:26:29 +08:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addInstantSearch(app) {
|
2018-03-31 03:30:30 +08:00
|
|
|
app.get('/api/instant-search/:text',
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 18:03:17 +08:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2017-06-11 04:32:56 +08:00
|
|
|
GalleryMWs.instantSearch,
|
|
|
|
ThumbnailGeneratorMWs.addThumbnailInformation,
|
2018-11-19 03:26:29 +08:00
|
|
|
GalleryMWs.cleanUpGalleryResults,
|
2017-06-11 04:32:56 +08:00
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-05-10 01:14:33 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private static addAutoComplete(app) {
|
2018-03-31 03:30:30 +08:00
|
|
|
app.get('/api/autocomplete/:text',
|
2017-06-11 04:32:56 +08:00
|
|
|
AuthenticationMWs.authenticate,
|
2017-07-09 18:03:17 +08:00
|
|
|
AuthenticationMWs.authorise(UserRoles.Guest),
|
2017-06-11 04:32:56 +08:00
|
|
|
GalleryMWs.autocomplete,
|
|
|
|
RenderingMWs.renderResult
|
|
|
|
);
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-03-20 00:31:42 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|