2016-03-20 02:59:19 +08:00
|
|
|
|
2016-03-20 17:49:49 +08:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as fs from 'fs';
|
2016-03-20 02:59:19 +08:00
|
|
|
import {NextFunction, Request, Response} from "express";
|
|
|
|
import {Error, ErrorCodes} from "../../common/entities/Error";
|
2016-03-20 17:49:49 +08:00
|
|
|
import {GalleryManager} from "../model/GalleryManager";
|
|
|
|
import {Directory} from "../../common/entities/Directory";
|
2016-03-20 02:59:19 +08:00
|
|
|
|
2016-03-26 18:19:10 +08:00
|
|
|
export class GalleryMWs {
|
2016-03-20 02:59:19 +08:00
|
|
|
|
2016-03-26 18:19:10 +08:00
|
|
|
|
2016-03-27 02:24:12 +08:00
|
|
|
public static listDirectory(req:Request, res:Response, next:NextFunction){
|
|
|
|
console.log("listDirectory");
|
|
|
|
console.log(req.params);
|
2016-03-20 17:49:49 +08:00
|
|
|
let directoryName = "/";
|
|
|
|
if(req.params.directory){
|
|
|
|
directoryName = req.params.directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
let absoluteDirectoryName = path.join(__dirname,"/../../demo/images", directoryName);
|
|
|
|
if(!fs.statSync(absoluteDirectoryName).isDirectory()){
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
GalleryManager.listDirectory(directoryName,(err,directory:Directory) => {
|
|
|
|
if(err || !directory){
|
2016-03-26 18:19:10 +08:00
|
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR,err));
|
2016-03-20 17:49:49 +08:00
|
|
|
}
|
2016-03-26 18:19:10 +08:00
|
|
|
req.resultPipe = directory;
|
|
|
|
return next();
|
2016-03-20 17:49:49 +08:00
|
|
|
});
|
2016-03-20 02:59:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-27 02:24:12 +08:00
|
|
|
public static loadImage(req:Request, res:Response, next:NextFunction){
|
|
|
|
console.log("loadImage");
|
|
|
|
console.log(req.params);
|
|
|
|
if(!(req.params.imagePath)){
|
2016-03-20 17:49:49 +08:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
2016-03-27 02:24:12 +08:00
|
|
|
let fullImagePath = path.join(__dirname,"/../../demo/images", req.params.imagePath);
|
2016-03-20 17:49:49 +08:00
|
|
|
if(fs.statSync(fullImagePath).isDirectory()){
|
|
|
|
return next();
|
|
|
|
}
|
2016-03-26 18:19:10 +08:00
|
|
|
|
|
|
|
req.resultPipe = fullImagePath;
|
|
|
|
return next();
|
2016-03-20 02:59:19 +08:00
|
|
|
}
|
|
|
|
|
2016-03-26 18:19:10 +08:00
|
|
|
public static loadThumbnail(req:Request, res:Response, next:NextFunction){
|
2016-03-20 02:59:19 +08:00
|
|
|
//TODO: implement
|
2016-03-26 18:19:10 +08:00
|
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
2016-03-20 02:59:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static search(req:Request, res:Response, next:NextFunction){
|
|
|
|
//TODO: implement
|
2016-03-26 18:19:10 +08:00
|
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
2016-03-20 02:59:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static autocomplete(req:Request, res:Response, next:NextFunction){
|
|
|
|
//TODO: implement
|
2016-03-26 18:19:10 +08:00
|
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
2016-03-20 02:59:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|