...
|
...
|
@@ -3,7 +3,17 @@ var _ = require('lodash'); |
|
|
var fs = require('fs');
|
|
|
var ipaddr = require('ipaddr.js');
|
|
|
var domain = require('../../config/common.js').domain;
|
|
|
// var domain = 'http://172.16.6.227:8088/platform'; //马力
|
|
|
|
|
|
//老上传地址
|
|
|
var oldUploadUrl = 'http://upload.static.yohobuy.com';
|
|
|
|
|
|
//上传异常的信息
|
|
|
var errBackMsg = {
|
|
|
code: "500",
|
|
|
message: "接口异常"
|
|
|
};
|
|
|
|
|
|
//var domain = 'http://172.16.6.227:8088/platform'; //马力
|
|
|
// var domain = 'http://172.16.6.162:8088/platform';
|
|
|
//var domain = 'http://172.16.6.240:8088/platform';
|
|
|
|
...
|
...
|
@@ -24,27 +34,53 @@ exports.uploadFile = function(req, res) { |
|
|
|
|
|
if (req.is("multipart/form-data")) {
|
|
|
console.log(req.body);
|
|
|
var url=[];
|
|
|
for(var key in req.body){
|
|
|
url.push(key+"="+req.body[key]);
|
|
|
}
|
|
|
req.body.file = fs.createReadStream(req.files[req.body.filename].path);
|
|
|
if (req.body.__type == "batch-import") {
|
|
|
request.post({
|
|
|
url: domain + '/batch/import',
|
|
|
url: domain + '/batch/import?'+url.join("&"),
|
|
|
formData: req.body,
|
|
|
headers: headers
|
|
|
}, function optionalCallback(error, httpResponse, body) {
|
|
|
console.log(body);
|
|
|
if (!error && httpResponse.statusCode == 200) {
|
|
|
var json = JSON.parse(body);
|
|
|
json.status = true;
|
|
|
res.json(json);
|
|
|
} else {
|
|
|
res.json(errBackMsg);
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
|
|
|
//如果是goodsimg(商品)的图片,灰度到老系统的上传地址
|
|
|
if(req.body.bucket === 'goodsimg') {
|
|
|
req.body.filename = req.files[req.body.filename].path;
|
|
|
request.post({
|
|
|
url: oldUploadUrl,
|
|
|
formData:{
|
|
|
fileData:req.body.file,
|
|
|
project:req.body.bucket
|
|
|
}
|
|
|
},function(error,resd,body) {
|
|
|
if(!error && resd.statusCode == 200) {
|
|
|
var ret = JSON.parse(body);
|
|
|
if(ret.code === 200) {
|
|
|
var imgUrl = ret.data.imagesList[0];
|
|
|
res.json({
|
|
|
code: "500",
|
|
|
message: "接口异常"
|
|
|
code:200,
|
|
|
data:joinimg(imgUrl),
|
|
|
message:'上传成功',
|
|
|
status:true
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
res.json(errBackMsg);
|
|
|
});
|
|
|
} else {
|
|
|
|
|
|
request.post({
|
|
|
url: domain + '/fileupload/upload',
|
|
|
formData: req.body
|
...
|
...
|
@@ -55,14 +91,12 @@ exports.uploadFile = function(req, res) { |
|
|
json.status = true;
|
|
|
res.json(json);
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: "500",
|
|
|
message: "接口异常"
|
|
|
});
|
|
|
res.json(errBackMsg);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: "500",
|
...
|
...
|
@@ -70,3 +104,18 @@ exports.uploadFile = function(req, res) { |
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组合全路径的图片地址
|
|
|
*/
|
|
|
function joinimg(url) {
|
|
|
var urlArr = url.split('/');
|
|
|
var domain = 'static.yhbimg.com/goodsimg';
|
|
|
var num = urlArr[urlArr.length-1].substr(1,1);
|
|
|
var url = domain + url;
|
|
|
if(num == 1) {
|
|
|
return 'http://img11.' + url;
|
|
|
} else {
|
|
|
return 'http://img12.'+ url;
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|