Comparing version 0.0.14 to 0.0.15
@@ -281,6 +281,7 @@ /** | ||
if (!err) { | ||
var tmpFileName = '.tmp-' + request.session.ftp_user.name; | ||
tmpFileName = pathModule.resolve(__dirname, path); | ||
// temp file at the root of unifile | ||
var tmpFileName = '../../.tmp-' + request.session.ftp_user.name + '-' + Math.round(Math.random()*1000); | ||
tmpFileName = pathModule.resolve(__dirname, tmpFileName); | ||
stream.pipe(fs.createWriteStream(tmpFileName)); | ||
ftpClient.put(dst, tmpFileName, function(err) { | ||
ftpClient.put(tmpFileName, dst, function(err) { | ||
fs.unlink(tmpFileName, function(){ | ||
@@ -291,3 +292,3 @@ if (!err) { | ||
else{ | ||
cbk({success:false, message: err.code}); | ||
cbk({success:false, message: err.message, code: err.code}); | ||
} | ||
@@ -298,3 +299,3 @@ }); | ||
else{ | ||
cbk({success:false, message: err.code}); | ||
cbk({success:false, message: err.message, code: err.code}); | ||
} | ||
@@ -316,4 +317,12 @@ }); | ||
} | ||
// TODO: use rename https://www.npmjs.org/package/ftp | ||
cbk({success:false, code:501, message: 'not implemented yet'}); | ||
console.log('mv', src, dst); | ||
exports.cp(src, dst, request, response, next, function(e){ | ||
if (e && e.success === true){ | ||
exports.rm(src, request, response, next, cbk); | ||
} | ||
else{ | ||
cbk(e); | ||
} | ||
}); | ||
} | ||
@@ -332,11 +341,16 @@ /** | ||
} | ||
ftpClient.put(data, path, function(err){ | ||
if (!err){ | ||
cbk({success:true}); | ||
} | ||
else{ | ||
cbk({success:false, message: err.code}); | ||
} | ||
}); | ||
try{ | ||
var buffer = new Buffer(data); | ||
ftpClient.put(buffer, path, function(err){ | ||
if (!err){ | ||
cbk({success:true}); | ||
} | ||
else{ | ||
cbk({success:false, message: err.message, code: err.code}); | ||
} | ||
}); | ||
} | ||
catch(err){ | ||
cbk({success:false, message: err.message, code: err.code}); | ||
} | ||
} | ||
@@ -359,13 +373,14 @@ /** | ||
if (!err) { | ||
var tmpFileName = '.tmp-' + request.session.ftp_user.name; | ||
tmpFileName = pathModule.resolve(__dirname, path); | ||
stream.pipe(fs.createWriteStream(tmpFileName)); | ||
fs.unlink(tmpFileName, function(){ | ||
cbk(undefined, undefined, undefined, tmpFileName); | ||
var data = []; | ||
stream.on('data', function (chunk) { | ||
data = data.concat(chunk); | ||
}); | ||
stream.once('end', function () { | ||
cbk({success:true}, data[0]); | ||
}); | ||
} | ||
else{ | ||
cbk({success:false, message: err.code}); | ||
cbk({success:false, message: err.message, code: err.code}); | ||
} | ||
}); | ||
} |
{ | ||
"name": "unifile", | ||
"description": "Express middleware to provide a common API for cloud storage services. ", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Alex Hoyau aka lexoyo" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103874
31
2338