mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-12-16 11:37:13 +02:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
|
|
import * as path from 'path';
|
|
import * as fs from 'fs';
|
|
import {NextFunction, Request, Response} from "express";
|
|
import {Error, ErrorCodes} from "../../common/entities/Error";
|
|
import {GalleryManager} from "../model/GalleryManager";
|
|
import {Directory} from "../../common/entities/Directory";
|
|
|
|
export class GalleryMWs {
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
let absoluteDirectoryName = path.join(__dirname,"/../../demo/images", directoryName);
|
|
if(!fs.statSync(absoluteDirectoryName).isDirectory()){
|
|
return next();
|
|
}
|
|
|
|
GalleryManager.listDirectory(directoryName,(err,directory:Directory) => {
|
|
if(err || !directory){
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR,err));
|
|
}
|
|
req.resultPipe = directory;
|
|
return next();
|
|
});
|
|
}
|
|
|
|
|
|
public static loadImage(req:Request, res:Response, next:NextFunction){
|
|
if(!(req.params.imagePath)){
|
|
return next();
|
|
}
|
|
|
|
let fullImagePath = path.join(__dirname,"/../../demo/images", req.params.imagePath);
|
|
if(fs.statSync(fullImagePath).isDirectory()){
|
|
return next();
|
|
}
|
|
|
|
req.resultPipe = fullImagePath;
|
|
return next();
|
|
}
|
|
|
|
|
|
|
|
|
|
public static search(req:Request, res:Response, next:NextFunction){
|
|
//TODO: implement
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
|
}
|
|
|
|
public static autocomplete(req:Request, res:Response, next:NextFunction){
|
|
//TODO: implement
|
|
return next(new Error(ErrorCodes.GENERAL_ERROR));
|
|
}
|
|
|
|
|
|
|
|
} |