utils.js
838 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
/**
* common 相关 utils
* @author: 刘传洋<chuanyang.liu@yoho.cn>
* @date: 2016/10/31
*/
/**
* 01=["img10.static.yhbimg.com", "img11.static.yhbimg.com"],
* 02=["img12.static.yhbimg.com", "img13.static.yhbimg.com"]
* 03=["flv01.static.yhbimg.com", "flv01.static.yhbimg.com"]
* @param url
* @param bucket
* @returns {*}
*/
'use strict';
const getUploadImgAbsoluteUrl = (url, bucket) => {
if (!url) {
return null;
}
let urlArr = url.split('/'),
stag = urlArr[urlArr.length - 1].substr(0, 2),
domain = `static.yhbimg.com/${bucket}`;
url = domain + url;
if (stag === '01') {
return `//img11.${url}`;
} else if (stag === '03') {
return `//flv01.${url}`;
} else {
return `//img12.${url}`;
}
};
module.exports = {
getUploadImgAbsoluteUrl
};