Authored by TaoHuang

fix upload

... ... @@ -66,19 +66,31 @@ export default {
return {
multiple: false,
action: {
target: '//upload.qiniup.com/',
target: '/mapp/upload',
data(file) {
return {
token: vm.token,
key: 'license/' + Date.now() + '/' + file.name
key: 'license/' + Date.now() + '/' + file.name,
bucket: 'goodsimg',
userId: vm.getUid(),
method: 'yoho.fileupload'
};
}
},
file: this.value,
initialIndex: 0
initialIndex: 0,
uid: ''
};
},
async mounted() {
const user = await this.$sdk.getUser();
this.uid = user.uid;
},
methods: {
getUid() {
return this.uid;
},
filesAdded(files) {
let hasIgnore = false;
const maxSize = 10 * 1024 * 1024; // 10M
... ... @@ -121,10 +133,10 @@ export default {
this.initialIndex = this.file.findIndex(i => file.name === i.name);
const imgs = this.file.map(f => {
return '//img01.yohoboys.com/' + f.response.key + '?imageView2/2/w/450/q/60';
return this.getUploadImgAbsoluteUrl(f.response.data, 'goodsimg') + '?imageView2/2/w/450/q/60';
});
if (file && file.response && file.response.key) {
if (file && file.response && file.response.data) {
this.$createImagePreview({
$props: {
imgs,
... ... @@ -145,6 +157,24 @@ export default {
},
fileRemove(file) {
this.$emit('file-change', file);
},
getUploadImgAbsoluteUrl(url, bucket) {
if (!url) {
return null;
}
let urlArr = url.split('/'),
stag = urlArr[urlArr.length - 1].substr(0, 2),
domain = `static.yhbimg.com/${bucket}`;
url = domain + url;
if (stag === '01') {
return `//img11.${url}`;
} else if (stag === '03') {
return `//flv01.${url}`;
} else {
return `//img12.${url}`;
}
}
},
computed: {
... ...
... ... @@ -88,6 +88,7 @@ exports.createApp = async(app) => {
app.use(setYohoDataMiddleware);
app.use(userMiddleware);
app.get('/mapp/getToken', qiniuMiddleware.getToken);
app.post('/mapp/upload', qiniuMiddleware.upload);
app.use('/mapp/alipay', alipayRouter);
app.use('/mapp', ssrApiMiddleware);
... ...
... ... @@ -6,6 +6,8 @@
const qiniu = require('qiniu');
const qiniuConfig = global.yoho.config.qiniu;
const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn;
const request = require('request');
const { config } = global.yoho;
function getToken(req, res) {
let conf = qiniuConfig;
... ... @@ -28,6 +30,17 @@ function getToken(req, res) {
});
}
function upload(req, res, next) {
let localReq = request(config.domains.api);
req.pipe(localReq).pipe(res);
localReq.on('error', function(err) {
next(err);
});
}
module.exports = {
getToken
getToken,
upload
};
... ...
... ... @@ -49,6 +49,7 @@
"lottie-web": "^5.4.2",
"mysql": "^2.16.0",
"qiniu": "^7.2.1",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"serve-favicon": "^2.5.0",
"source-map": "^0.7.3",
... ...