qiniu.js 862 Bytes
/**
 *
 * @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;