...
|
...
|
@@ -10,16 +10,16 @@ const request = require('request'); |
|
|
const fs = require('fs');
|
|
|
|
|
|
// 获取图片绝对地址
|
|
|
const getImgHost = (url) => {
|
|
|
let domain = 'static.yhbimg.com/goodsimg',
|
|
|
const getImgHost = (url, bucket) => {
|
|
|
let domain = `static.yhbimg.com/${bucket}`,
|
|
|
urlArr = url.split('/'),
|
|
|
num = urlArr[urlArr.length - 1].substr(1, 1),
|
|
|
url1 = domain + url;
|
|
|
|
|
|
if (num === '1') {
|
|
|
return 'http://img11.' + url1;
|
|
|
return `http://img11.${url1}`;
|
|
|
} else {
|
|
|
return 'http://img12.' + url1;
|
|
|
return `http://img12.${url1}`;
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -45,41 +45,35 @@ const uploadImg = (req, res) => { |
|
|
req.body.fileNames[fileIndex] = files[fileIndex].name;
|
|
|
}
|
|
|
|
|
|
if (req.body.bucket === 'goodsimg') {
|
|
|
request.post({
|
|
|
url: 'http://upload.static.yohobuy.com',
|
|
|
formData: {
|
|
|
fileData: req.body.files,
|
|
|
project: req.body.bucket
|
|
|
},
|
|
|
json: true
|
|
|
}, (error, httpResponse, rebody) => {
|
|
|
if (!error && httpResponse.statusCode === 200) {
|
|
|
imgs = rebody.data.imagesList || [];
|
|
|
datas = [];
|
|
|
request.post({
|
|
|
url: 'http://upload.static.yohobuy.com',
|
|
|
formData: {
|
|
|
fileData: req.body.files,
|
|
|
project: req.body.bucket
|
|
|
},
|
|
|
json: true
|
|
|
}, (error, httpResponse, rebody) => {
|
|
|
console.log(httpResponse);
|
|
|
if (!error && httpResponse.statusCode === 200) {
|
|
|
imgs = rebody.data.imagesList || [];
|
|
|
datas = [];
|
|
|
|
|
|
// 生成图片绝对地址
|
|
|
for (i = 0; i < imgs.length; i++) {
|
|
|
datas.push(getImgHost(imgs[i]));
|
|
|
}
|
|
|
// 生成图片绝对地址
|
|
|
for (i = 0; i < imgs.length; i++) {
|
|
|
datas.push(getImgHost(imgs[i], req.body.bucket));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: datas[0],
|
|
|
datas: datas,
|
|
|
imgs: imgs,
|
|
|
names: req.body.fileNames,
|
|
|
message: '上传成功',
|
|
|
status: true
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 500,
|
|
|
message: '上传图片失败, 请稍后重试!'
|
|
|
code: 200,
|
|
|
data: datas[0],
|
|
|
datas: datas,
|
|
|
imgs: imgs,
|
|
|
names: req.body.fileNames,
|
|
|
message: '上传成功',
|
|
|
status: true
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 401,
|
...
|
...
|
|