@ -104,46 +104,25 @@ var nconf = require('nconf'),
return res . redirect ( '/403' ) ;
var allowedTypes = [ 'image/png' , 'image/jpeg' , 'image/jpg' , 'image/gif' ] ;
if ( allowedTypes . indexOf ( req . files . userPhoto . type ) === - 1 ) {
res . send ( {
error : 'Allowed image types are png, jpg and gif!'
var params = null ;
try {
params = JSON . parse ( req . body . params ) ;
} catch ( e ) {
return res . send ( {
error : 'Error uploading file! Error :' + e . message
} ) ;
return ;
}
var tempPath = req . files . userPhoto . path ;
var extension = path . extname ( req . files . userPhoto . name ) ;
if ( ! extension ) {
if ( allowedTypes . indexOf ( req . files . userPhoto . type ) === - 1 ) {
res . send ( {
error : ' Error uploading file! Error : Invalid extension !'
error : 'Allowed image types are png, jpg and gif!'
} ) ;
return ;
}
var filename = 'category' + utils . generateUUID ( ) + extension ;
var uploadPath = path . join ( nconf . get ( 'base_dir' ) , nconf . get ( 'upload_path' ) , filename ) ;
winston . info ( 'Attempting upload to: ' + uploadPath ) ;
var is = fs . createReadStream ( tempPath ) ;
var os = fs . createWriteStream ( uploadPath ) ;
is . on ( 'end' , function ( ) {
fs . unlinkSync ( tempPath ) ;
console . log ( nconf . get ( 'upload_url' ) + filename ) ;
res . json ( {
path : nconf . get ( 'upload_url' ) + filename
} ) ;
} ) ;
os . on ( 'error' , function ( err ) {
fs . unlinkSync ( tempPath ) ;
winston . err ( err ) ;
} ) ;
var filename = 'category-' + params . cid + path . extname ( req . files . userPhoto . name ) ;
is. pipe ( o s) ;
uploadImage ( filename , req , res ) ;
} ) ;
app . post ( '/uploadfavicon' , function ( req , res ) {
@ -159,38 +138,7 @@ var nconf = require('nconf'),
return ;
}
var tempPath = req . files . userPhoto . path ;
var extension = path . extname ( req . files . userPhoto . name ) ;
if ( ! extension ) {
res . send ( {
error : 'Error uploading file! Error : Invalid extension!'
} ) ;
return ;
}
var filename = 'favicon.ico' ;
var uploadPath = path . join ( nconf . get ( 'base_dir' ) , nconf . get ( 'upload_path' ) , filename ) ;
winston . info ( 'Attempting upload to: ' + uploadPath ) ;
var is = fs . createReadStream ( tempPath ) ;
var os = fs . createWriteStream ( uploadPath ) ;
is . on ( 'end' , function ( ) {
fs . unlinkSync ( tempPath ) ;
res . json ( {
path : nconf . get ( 'upload_url' ) + filename
} ) ;
} ) ;
os . on ( 'error' , function ( err ) {
fs . unlinkSync ( tempPath ) ;
winston . err ( err ) ;
} ) ;
is . pipe ( os ) ;
uploadImage ( 'favicon.ico' , req , res ) ;
} ) ;
app . post ( '/uploadlogo' , function ( req , res ) {
@ -207,40 +155,45 @@ var nconf = require('nconf'),
return ;
}
var tempPath = req . files . userPhoto . path ;
var extension = path . extname ( req . files . userPhoto . name ) ;
var filename = 'site-logo' + path . extname ( req . files . userPhoto . name ) ;
if ( ! extension ) {
res . send ( {
error : 'Error uploading file! Error : Invalid extension!'
} ) ;
return ;
}
uploadImage ( filename , req , res ) ;
} ) ;
} ) ;
var filename = 'site-logo' + extension ;
var uploadPath = path . join ( nconf . get ( 'base_dir' ) , nconf . get ( 'upload_path' ) , filename ) ;
function uploadImage ( filename , req , res ) {
winston . info ( 'Attempting upload to: ' + uploadPath ) ;
var tempPath = req . files . userPhoto . path ;
var extension = path . extname ( req . files . userPhoto . name ) ;
var is = fs . createReadStream ( tempPath ) ;
var os = fs . createWriteStream ( uploadPath ) ;
if ( ! extension ) {
res . send ( {
error : 'Error uploading file! Error : Invalid extension!'
} ) ;
return ;
}
is . on ( 'end' , function ( ) {
fs . unlinkSync ( tempPath ) ;
var uploadPath = path . join ( nconf . get ( 'base_dir' ) , nconf . get ( 'upload_path' ) , filename ) ;
res . json ( {
path : nconf . get ( 'upload_url' ) + filename
} ) ;
} ) ;
winston . info ( 'Attempting upload to: ' + uploadPath ) ;
var is = fs . createReadStream ( tempPath ) ;
var os = fs . createWriteStream ( uploadPath ) ;
is . on ( 'end' , function ( ) {
fs . unlinkSync ( tempPath ) ;
os . on ( 'error' , function ( err ) {
fs . unlinkSync ( tempPath ) ;
winston . err ( err ) ;
res . json ( {
path : nconf . get ( 'upload_url' ) + filename
} ) ;
} ) ;
is . pipe ( os ) ;
os . on ( 'error' , function ( err ) {
fs . unlinkSync ( tempPath ) ;
winston . err ( err ) ;
} ) ;
} ) ;
is . pipe ( os ) ;
}
var custom _routes = {