src/base.js
function getUrl(params) {
    var longBucket = params.bucket;
    var shortBucket = longBucket.substr(0, longBucket.lastIndexOf('-'));
    var appId = longBucket.substr(longBucket.lastIndexOf('-') + 1);
    var domain = params.domain;
    var region = params.region;
    var object = params.object;
    var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
    if (!domain) {
        if (['cn-south', 'cn-south-2', 'cn-north', 'cn-east', 'cn-southwest', 'sg'].indexOf(region) > -1) {
            domain = '{Region}.myqcloud.com';
        } else {
            domain = 'cos.{Region}.myqcloud.com';
        }
        if (!params.ForcePathStyle) {
            domain = '{Bucket}.' + domain;
        }
    }
    domain = domain.replace(/\{\{AppId\}\}/ig, appId)
        .replace(/\{\{Bucket\}\}/ig, shortBucket)
        .replace(/\{\{Region\}\}/ig, region)
        .replace(/\{\{.*?\}\}/ig, '');
    domain = domain.replace(/\{AppId\}/ig, appId)
        .replace(/\{BucketName\}/ig, shortBucket)
        .replace(/\{Bucket\}/ig, longBucket)
        .replace(/\{Region\}/ig, region)
        .replace(/\{.*?\}/ig, '');
    if (!/^[a-zA-Z]+:\/\//.test(domain)) {
        domain = protocol + '//' + domain;
    }

    // 去掉域名最后的斜杆
    if (domain.slice(-1) === '/') {
        domain = domain.slice(0, -1);
    }
    var url = domain;

    if (params.ForcePathStyle) {
        url += '/' + longBucket;
    }
    url += '/';
    if (object) {
        url += util.camSafeUrlEncode(object).replace(/%2F/g, '/');
    }

    if (params.isLocation) {
        url = url.replace(/^https?:\/\//, '');
    }
    return url;
}
function getUrl(params) {
    var longBucket = params.bucket;
    var shortBucket = longBucket.substr(0, longBucket.lastIndexOf('-'));
    var appId = longBucket.substr(longBucket.lastIndexOf('-') + 1);
    var domain = params.domain;
    var region = params.region;
    var object = params.object;
    var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
    if (!domain) {
        if (['cn-south', 'cn-south-2', 'cn-north', 'cn-east', 'cn-southwest', 'sg'].indexOf(region) > -1) {
            domain = '{Region}.myqcloud.com';
        } else {
            domain = 'cos.{Region}.myqcloud.com';
        }
        if (!params.ForcePathStyle) {
            domain = '{Bucket}.' + domain;
        }
    }
    domain = domain.replace(/\{\{AppId\}\}/ig, appId)
        .replace(/\{\{Bucket\}\}/ig, shortBucket)
        .replace(/\{\{Region\}\}/ig, region)
        .replace(/\{\{.*?\}\}/ig, '');
    domain = domain.replace(/\{AppId\}/ig, appId)
        .replace(/\{BucketName\}/ig, shortBucket)
        .replace(/\{Bucket\}/ig, longBucket)
        .replace(/\{Region\}/ig, region)
        .replace(/\{.*?\}/ig, '');
    if (!/^[a-zA-Z]+:\/\//.test(domain)) {
        domain = protocol + '//' + domain;
    }

    // 去掉域名最后的斜杆
    if (domain.slice(-1) === '/') {
        domain = domain.slice(0, -1);
    }
    var url = domain;

    if (params.ForcePathStyle) {
        url += '/' + longBucket;
    }
    url += '/';
    if (object) {
        url += util.camSafeUrlEncode(object).replace(/%2F/g, '/');
    }

    if (params.isLocation) {
        url = url.replace(/^https?:\/\//, '');
    }
    return url;
}
function getUrl ( params ) { var longBucket = params . bucket ; var shortBucket = longBucket . substr ( 0 , longBucket . lastIndexOf ( '-' ) ) ; var appId = longBucket . substr ( longBucket . lastIndexOf ( '-' ) + 1 ) ; var domain = params . domain ; var region = params . region ; var object = params . object ; var protocol = params . protocol || ( util . isBrowser && location . protocol === 'http:' ? 'http:' : 'https:' ) ; if ( ! domain ) { if ( [ 'cn-south' , 'cn-south-2' , 'cn-north' , 'cn-east' , 'cn-southwest' , 'sg' ] . indexOf ( region ) > - 1 ) { domain = '{Region}.myqcloud.com' ; } else { domain = 'cos.{Region}.myqcloud.com' ; } if ( ! params . ForcePathStyle ) { domain = '{Bucket}.' + domain ; } } domain = domain . replace ( / \{\{AppId\}\} / ig , appId ) . replace ( / \{\{Bucket\}\} / ig , shortBucket ) . replace ( / \{\{Region\}\} / ig , region ) . replace ( / \{\{.*?\}\} / ig , '' ) ; domain = domain . replace ( / \{AppId\} / ig , appId ) . replace ( / \{BucketName\} / ig , shortBucket ) . replace ( / \{Bucket\} / ig , longBucket ) . replace ( / \{Region\} / ig , region ) . replace ( / \{.*?\} / ig , '' ) ; if ( ! / ^[a-zA-Z]+:\/\/ / . test ( domain ) ) { domain = protocol + '//' + domain ; } // 去掉域名最后的斜杆 if ( domain . slice ( - 1 ) === '/' ) { domain = domain . slice ( 0 , - 1 ) ; } var url = domain ; if ( params . ForcePathStyle ) { url += '/' + longBucket ; } url += '/' ; if ( object ) { url += util . camSafeUrlEncode ( object ) . replace ( / %2F / g , '/' ) ; } if ( params . isLocation ) { url = url . replace ( / ^https?:\/\/ / , '' ) ; } return url ; }
生成操作 url
生成操作 url