...
|
...
|
@@ -7,25 +7,29 @@ const qiniu = require('qiniu'); |
|
|
const qiniuConfig = global.yoho.config.qiniu;
|
|
|
const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn;
|
|
|
|
|
|
function getToken(req, res) {
|
|
|
let conf = qiniuConfig;
|
|
|
let type = req.query.type || '';
|
|
|
function getToken(req, res, next) {
|
|
|
try {
|
|
|
let conf = qiniuConfig;
|
|
|
let type = req.query.type || '';
|
|
|
|
|
|
if (type.toLowerCase() === 'yohocdn') {
|
|
|
conf = qiniuYohoCdnConfig;
|
|
|
}
|
|
|
if (type.toLowerCase() === 'yohocdn') {
|
|
|
conf = qiniuYohoCdnConfig;
|
|
|
}
|
|
|
|
|
|
let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
|
|
|
let options = {
|
|
|
scope: conf.BUCKET_NAME
|
|
|
};
|
|
|
let putPolicy = new qiniu.rs.PutPolicy(options);
|
|
|
let uploadToken = putPolicy.uploadToken(mac);
|
|
|
let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
|
|
|
let options = {
|
|
|
scope: conf.BUCKET_NAME
|
|
|
};
|
|
|
let putPolicy = new qiniu.rs.PutPolicy(options);
|
|
|
let uploadToken = putPolicy.uploadToken(mac);
|
|
|
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
uptoken: uploadToken
|
|
|
});
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
uptoken: uploadToken
|
|
|
});
|
|
|
} catch (e) {
|
|
|
return next(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|