Skip to content

Commit

Permalink
fix: 添加protocol选项,提供输出文件路径的协议覆盖能力,默认文件路径变更为https协议
Browse files Browse the repository at this point in the history
  • Loading branch information
TabSpace committed Feb 19, 2019
1 parent efe24f6 commit 742cd3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ upload({
overwrite: false,
// 为 true 则输出文件路径为腾讯云默认 CDN 地址。为具体域名,则替换腾讯云默认 CDN 域名。
cdn: '',
// 文件远程路径协议,默认为 'https:',这个选项仅影响输出结果。
protocol: 'https:',
// 在腾讯云申请的 AppId
AppId: '1000000000',
// 配置腾讯云 COS 服务所需的 SecretId
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function upload(options) {
options = options || {};

let conf = Object.assign({
// 输出文件路径协议
protocol: 'https:',
// 静态资源对应 cdn 域名,配置后,打印在控制台的日志自动替换域名显示
// 配置为 true ,自动匹配腾讯云 cdn 域名
cdn: '',
Expand All @@ -123,13 +125,13 @@ function upload(options) {
}, requestParam, options);

conf.domain = `${conf.Bucket}-${conf.AppId}.coscd.myqcloud.com`;
conf.cosUrl = $urljoin(`http://${conf.domain}`, conf.Key);
conf.cosUrl = $urljoin(`${conf.protocol}//${conf.domain}`, conf.Key);

if (conf.cdn === true) {
let cdnDomain = `${conf.Bucket}-${conf.AppId}.file.myqcloud.com`;
conf.cdnUrl = $urljoin(`http://${cdnDomain}`, conf.Key);
conf.cdnUrl = $urljoin(`${conf.protocol}//${cdnDomain}`, conf.Key);
} else if (conf.cdn) {
conf.cdnUrl = $urljoin(`http://${conf.cdn}`, conf.Key);
conf.cdnUrl = $urljoin(`${conf.protocol}//${conf.cdn}`, conf.Key);
}
if (conf.Bucket.indexOf('-') < 0) {
conf.Bucket = conf.Bucket + '-' + conf.AppId;
Expand Down

0 comments on commit 742cd3f

Please sign in to comment.