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

implementing config

This commit is contained in:
Braun Patrik 2016-04-09 23:09:28 +02:00
parent 65d88fe061
commit 8ad13e3e78
3 changed files with 30 additions and 9 deletions

6
backend/config/Config.ts Normal file
View File

@ -0,0 +1,6 @@
export class Config{
public static thumbnailSizes = [200];
public static imagesFolder = "/demo/images";
public static thumbnailFolder = "/demo/TEMP";
}

View File

@ -4,14 +4,19 @@ 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";
import {Directory} from "../../common/entities/Directory";
import {Config} from "../config/Config";
export class GalleryMWs {
private static getImageFolder(){
return path.join(__dirname,"/../../",Config.imagesFolder);
}
public static listDirectory(req:Request, res:Response, next:NextFunction){
let directoryName = req.params.directory || "/";
let absoluteDirectoryName = path.join(__dirname,"/../../demo/images", directoryName);
let absoluteDirectoryName = path.join(GalleryMWs.getImageFolder(), directoryName);
if(!fs.statSync(absoluteDirectoryName).isDirectory()){
return next();
@ -32,7 +37,7 @@ export class GalleryMWs {
return next();
}
let fullImagePath = path.join(__dirname,"/../../demo/images", req.params.imagePath);
let fullImagePath = path.join(GalleryMWs.getImageFolder(), req.params.imagePath);
if(fs.statSync(fullImagePath).isDirectory()){
return next();
}

View File

@ -7,29 +7,39 @@ import * as crypto from 'crypto';
import * as fs from 'fs';
import {NextFunction, Request, Response} from "express";
import {Error, ErrorCodes} from "../../common/entities/Error";
import {Config} from "../config/Config";
export class ThumbnailGeneratorMWs {
private static getThumbnailFolder(){
return path.join(__dirname,"/../../",Config.thumbnailFolder);
}
public static generateThumbnail(req:Request, res:Response, next:NextFunction){
if(!req.resultPipe)
return next();
let imagePath = req.resultPipe;
let size:number = parseInt(req.params.size) || 200; //TODO:put to config
let size:number = parseInt(req.params.size) || Config.thumbnailSizes[0];
let thumbnailFolder = ThumbnailGeneratorMWs.getThumbnailFolder();
if(Config.thumbnailSizes.indexOf(size) === -1){
size = Config.thumbnailSizes[0];
}
let thPath = path.join(__dirname,"/../../demo/TEMP",ThumbnailGeneratorMWs.generateThumbnailName(imagePath,size));
let thPath = path.join(thumbnailFolder,ThumbnailGeneratorMWs.generateThumbnailName(imagePath,size));
req.resultPipe = thPath;
if(fs.existsSync(thPath) === true){
return next();
}
let tmpDir = path.join(__dirname,"/../../demo/TEMP");
if (!fs.existsSync(tmpDir)){
fs.mkdirSync(tmpDir);
if (!fs.existsSync(thumbnailFolder)){
fs.mkdirSync(thumbnailFolder);
}
Jimp.read(imagePath).then( (image) => {