1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2016-03-19 19:59:19 +01:00
2016-03-20 10:49:49 +01:00
import * as path from 'path';
import * as fs from 'fs';
2016-03-19 19:59:19 +01:00
import {NextFunction, Request, Response} from "express";
import {Error, ErrorCodes} from "../../common/entities/Error";
2016-04-22 13:23:44 +02:00
import {GalleryManager} from "../model/memory/GalleryManager";
2016-04-09 23:09:28 +02:00
import {Directory} from "../../common/entities/Directory";
import {Config} from "../config/Config";
2016-04-22 13:23:44 +02:00
import {ObjectManagerRepository} from "../model/ObjectManagerRepository";
2016-03-19 19:59:19 +01:00
export class GalleryMWs {
2016-03-19 19:59:19 +01:00
2016-04-09 23:09:28 +02:00
private static getImageFolder(){
return path.join(__dirname,"/../../",Config.imagesFolder);
}
2016-03-26 19:24:12 +01:00
public static listDirectory(req:Request, res:Response, next:NextFunction){
let directoryName = req.params.directory || "/";
2016-04-09 23:09:28 +02:00
let absoluteDirectoryName = path.join(GalleryMWs.getImageFolder(), directoryName);
2016-03-20 10:49:49 +01:00
if(!fs.statSync(absoluteDirectoryName).isDirectory()){
return next();
}
2016-04-22 13:23:44 +02:00
ObjectManagerRepository.getInstance().getGalleryManager().listDirectory(directoryName,(err,directory:Directory) => {
2016-03-20 10:49:49 +01:00
if(err || !directory){
return next(new Error(ErrorCodes.GENERAL_ERROR,err));
2016-03-20 10:49:49 +01:00
}
req.resultPipe = directory;
return next();
2016-03-20 10:49:49 +01:00
});
2016-03-19 19:59:19 +01:00
}
2016-03-26 19:24:12 +01:00
public static loadImage(req:Request, res:Response, next:NextFunction){
if(!(req.params.imagePath)){
2016-03-20 10:49:49 +01:00
return next();
}
2016-04-09 23:09:28 +02:00
let fullImagePath = path.join(GalleryMWs.getImageFolder(), req.params.imagePath);
2016-03-20 10:49:49 +01:00
if(fs.statSync(fullImagePath).isDirectory()){
return next();
}
req.resultPipe = fullImagePath;
return next();
2016-03-19 19:59:19 +01:00
}
2016-03-29 21:46:44 +02:00
2016-03-19 19:59:19 +01:00
public static search(req:Request, res:Response, next:NextFunction){
//TODO: implement
return next(new Error(ErrorCodes.GENERAL_ERROR));
2016-03-19 19:59:19 +01:00
}
public static autocomplete(req:Request, res:Response, next:NextFunction){
//TODO: implement
return next(new Error(ErrorCodes.GENERAL_ERROR));
2016-03-19 19:59:19 +01:00
}
}