qiniu.js
862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/8/19
*/
'use strict';
const CDNCONFIG = require('../config/cdn_config');
const qn = require('qn');
const Promise = require('bluebird');
const _ = require('lodash');
const _default = (params) => {
let finalConfig = _.cloneDeep(CDNCONFIG.main);
if (params) {
_.assign(finalConfig, params);
// 传 key 强制覆盖
if (params.key) {
finalConfig.bucket = params.bucket + ':' + params.key;
}
}
return Promise.promisifyAll(
qn.create(finalConfig)
);
}
/**
* 兼容旧的强制覆盖逻辑,新功能开发弃用
*/
_default.key = function(key) {
let _conifg = _.clone(CDNCONFIG.main);
_conifg.bucket = _conifg.bucket + ":" + key;
return Promise.promisifyAll(qn.create(_conifg));
};
module.exports = _default;