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

105 lines
3.0 KiB
TypeScript
Raw Normal View History

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';
2016-05-09 23:04:56 +08:00
export class GalleryRouter {
public static route(app: any) {
this.addGetImageIcon(app);
this.addGetImageThumbnail(app);
this.addGetImage(app);
this.addRandom(app);
this.addDirectoryList(app);
this.addSearch(app);
this.addInstantSearch(app);
this.addAutoComplete(app);
}
private static addDirectoryList(app) {
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,
GalleryMWs.removeCyclicDirectoryReferences,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
private static addGetImage(app) {
2018-03-31 03:30:30 +08:00
app.get(['/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))'],
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
GalleryMWs.loadImage,
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
private static addRandom(app) {
app.get(['/api/gallery/random'],
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Guest),
// TODO: authorize path
GalleryMWs.getRandomImage,
GalleryMWs.loadImage,
RenderingMWs.renderFile
);
}
private static addGetImageThumbnail(app) {
2018-03-31 03:30:30 +08:00
app.get('/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?',
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
GalleryMWs.loadImage,
ThumbnailGeneratorMWs.generateThumbnail,
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
private static addGetImageIcon(app) {
2018-03-31 03:30:30 +08:00
app.get('/api/gallery/content/:imagePath(*\.(jpg|bmp|png|gif|jpeg))/icon',
AuthenticationMWs.authenticate,
2018-03-31 03:30:30 +08:00
// TODO: authorize path
GalleryMWs.loadImage,
ThumbnailGeneratorMWs.generateIcon,
RenderingMWs.renderFile
);
2018-03-31 03:30:30 +08:00
}
private static addSearch(app) {
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,
GalleryMWs.removeCyclicDirectoryReferences,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
private static addInstantSearch(app) {
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,
GalleryMWs.removeCyclicDirectoryReferences,
RenderingMWs.renderResult
);
2018-03-31 03:30:30 +08:00
}
private static addAutoComplete(app) {
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
}
}