mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
improving routing
This commit is contained in:
parent
b8963eb3e4
commit
f8db033c56
@ -10,10 +10,10 @@ import {UserRoles} from "../../common/entities/User";
|
||||
export class AuthenticationMWs {
|
||||
|
||||
|
||||
public static authenticate(req:Request, res:Response, next:NextFunction){
|
||||
if (typeof req.session.user === 'undefined') {
|
||||
public static authenticate(req:Request, res:Response, next:NextFunction){
|
||||
/* if (typeof req.session.user === 'undefined') {
|
||||
return next(new Error(ErrorCodes.NOT_AUTHENTICATED));
|
||||
}
|
||||
}*/
|
||||
return next();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,9 @@ import {Directory} from "../../common/entities/Directory";
|
||||
export class GalleryMWs {
|
||||
|
||||
|
||||
public static listDirectory(req:Request, res:Response, next:NextFunction){
|
||||
public static listDirectory(req:Request, res:Response, next:NextFunction){
|
||||
console.log("listDirectory");
|
||||
console.log(req.params);
|
||||
let directoryName = "/";
|
||||
if(req.params.directory){
|
||||
directoryName = req.params.directory;
|
||||
@ -30,16 +32,14 @@ export class GalleryMWs {
|
||||
}
|
||||
|
||||
|
||||
public static loadImage(req:Request, res:Response, next:NextFunction){
|
||||
let directoryName = "/";
|
||||
if(req.params.directory){
|
||||
directoryName = req.params.directory;
|
||||
}
|
||||
if(!(req.params.image)){
|
||||
public static loadImage(req:Request, res:Response, next:NextFunction){
|
||||
console.log("loadImage");
|
||||
console.log(req.params);
|
||||
if(!(req.params.imagePath)){
|
||||
return next();
|
||||
}
|
||||
|
||||
let fullImagePath = path.join(__dirname,"/../../demo/images", directoryName,req.params.image);
|
||||
let fullImagePath = path.join(__dirname,"/../../demo/images", req.params.imagePath);
|
||||
if(fs.statSync(fullImagePath).isDirectory()){
|
||||
return next();
|
||||
}
|
||||
|
@ -7,16 +7,16 @@ import {RenderingMWs} from "../middlewares/RenderingMWs";
|
||||
export class GalleryRouter{
|
||||
constructor(private app){
|
||||
|
||||
this.addDirectoryList();
|
||||
this.addGetImageThumbnail();
|
||||
this.addGetImage();
|
||||
this.addDirectoryList();
|
||||
|
||||
this.addSearch();
|
||||
this.addAutoComplete();
|
||||
}
|
||||
|
||||
private addDirectoryList() {
|
||||
this.app.get(["/api/gallery/:directory","/api/gallery/","/api/gallery//"],
|
||||
this.app.get(["/api/gallery/:directory(*)","/api/gallery/","/api/gallery//"],
|
||||
AuthenticationMWs.authenticate,
|
||||
GalleryMWs.listDirectory,
|
||||
RenderingMWs.renderResult
|
||||
@ -25,7 +25,7 @@ export class GalleryRouter{
|
||||
|
||||
|
||||
private addGetImage() {
|
||||
this.app.get(["/api/gallery/:directory/:image","/api/gallery/:image"],
|
||||
this.app.get(["/api/gallery/:imagePath(*\.(jpg|bmp|png|gif|jpeg))"],
|
||||
AuthenticationMWs.authenticate,
|
||||
GalleryMWs.loadImage,
|
||||
RenderingMWs.renderFile
|
||||
|
@ -12,7 +12,7 @@ export class PublicRouter{
|
||||
var renderIndex = (req: _express.Request, res: _express.Response) => {
|
||||
res.sendFile(_path.resolve(__dirname, './../../frontend/index.html'));
|
||||
};
|
||||
this.app.get(['/login',"/gallery"], renderIndex);
|
||||
this.app.get(['/login',"/gallery*"], renderIndex);
|
||||
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,20 @@ export class Server {
|
||||
*/
|
||||
// for parsing application/json
|
||||
this.app.use(_bodyParser.json());
|
||||
|
||||
|
||||
this.app.use("/testDir/:img(*\.(jpg|bmp))",(req,res,next)=>{
|
||||
console.log(req.params);
|
||||
res.send(req.params);
|
||||
});
|
||||
this.app.use("/testDir/:dir(*)",(req,res,next)=>{
|
||||
console.log(req.params);
|
||||
res.send(req.params);
|
||||
});
|
||||
|
||||
this.app.use("/testDir/*",(req,res,next)=>{
|
||||
console.log(req.params);
|
||||
res.send(req.params);
|
||||
});
|
||||
|
||||
new PublicRouter(this.app);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import {Router, Location} from "angular2/router";
|
||||
import {HTTP_PROVIDERS} from "angular2/http";
|
||||
import {UserService} from "./model/user.service";
|
||||
import {GalleryService} from "./gallery/gallery.service";
|
||||
import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path";
|
||||
|
||||
|
||||
|
||||
@ -32,10 +33,13 @@ import {GalleryService} from "./gallery/gallery.service";
|
||||
name: 'Login',
|
||||
component: LoginComponent,
|
||||
useAsDefault: true
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/gallery/:directory',
|
||||
regex: '/gallery(/([\S]*))?',
|
||||
name: 'Gallery',
|
||||
serializer: (params): GeneratedUrl => {
|
||||
return new GeneratedUrl(`/gallery/${params['directory']}`, {})
|
||||
},
|
||||
component: GalleryComponent
|
||||
}
|
||||
])
|
||||
|
@ -1 +1 @@
|
||||
<a [routerLink]="['Gallery',{directory: directory.name}]">{{directory.name}}</a>
|
||||
<a [routerLink]="['Gallery',{directory: getDirectoryPath()}]">{{directory.name}}</a>
|
@ -3,6 +3,7 @@
|
||||
import {Component, Input, OnInit} from 'angular2/core';
|
||||
import {Directory} from "../../../../common/entities/Directory";
|
||||
import {RouterLink} from "angular2/router";
|
||||
import {Utils} from "../../../../common/Utils";
|
||||
|
||||
@Component({
|
||||
selector: 'gallery-directory',
|
||||
@ -15,6 +16,10 @@ export class GalleryDirectoryComponent{
|
||||
constructor() {
|
||||
}
|
||||
|
||||
getDirectoryPath(){
|
||||
return Utils.concatUrls(this.directory.path,this.directory.name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ export class GalleryComponent implements OnInit{
|
||||
this._router.navigate(['Login']);
|
||||
return;
|
||||
}
|
||||
console.log(this._params.get('directory'));
|
||||
let directoryName = this._params.get('directory');
|
||||
directoryName = directoryName ? directoryName : "";
|
||||
this._galleryService.getDirectory(directoryName).then(( message:Message<Directory>) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
///<reference path="../../../browser.d.ts"/>
|
||||
|
||||
import {Component, Input, OnInit} from 'angular2/core';
|
||||
import {Component, Input} from 'angular2/core';
|
||||
import {Photo} from "../../../../common/entities/Photo";
|
||||
import {Directory} from "../../../../common/entities/Directory";
|
||||
import {Utils} from "../../../../common/Utils";
|
||||
@ -17,7 +17,6 @@ export class GalleryPhotoComponent{
|
||||
}
|
||||
|
||||
getPhotoPath(){
|
||||
console.log(Utils.concatUrls("/api/gallery",this.directory.path,this.directory.name,this.photo.name));
|
||||
return Utils.concatUrls("/api/gallery",this.directory.path,this.directory.name,this.photo.name);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user