hexo/node_modules/ali-oss/lib/common/utils/setRegion.ts

16 lines
588 B
TypeScript
Raw Normal View History

2023-10-03 11:14:36 +08:00
import urlutil from 'url';
import { checkConfigValid } from './checkConfigValid';
export function setRegion(region: string, internal = false, secure = false) {
checkConfigValid(region, 'region');
const protocol = secure ? 'https://' : 'http://';
let suffix = internal ? '-internal.aliyuncs.com' : '.aliyuncs.com';
const prefix = 'vpc100-oss-cn-';
// aliyun VPC region: https://help.aliyun.com/knowledge_detail/38740.html
if (region.substr(0, prefix.length) === prefix) {
suffix = '.aliyuncs.com';
}
return urlutil.parse(protocol + region + suffix);
}