olympus-r-17plugins
Version:
A plugin of Olympus for 17zuoye.
42 lines (41 loc) • 1.21 kB
JavaScript
import { environment17, EnvCode } from "../env/Environment17";
import { wrapHost, isAbsolutePath, validateProtocol } from "olympus-r/utils/URLUtil";
/**
* @author Raykid
* @email initial_r@qq.com
* @create date 2018-02-07
* @modify date 2018-02-07
*
* 头像工具集
*/
/**
* 获取头像URL
* @param headName 头像名称
* @param width 头像宽度
* @returns {string} 头像URL
*/
export function getHeadUrl(headName, width) {
if (headName == null || headName == "")
return null;
var host = "https://cdn-portrait.test.17zuoye.net/";
switch (environment17.envCode) {
case EnvCode.staging:
host = "https://cdn-portrait.17zuoye.cn/";
break;
case EnvCode.prod:
host = "https://cdn-portrait.17zuoye.cn/";
break;
}
var url;
if (isAbsolutePath(headName)) {
url = headName + "@" + width + "w";
}
else {
if (headName.indexOf("gridfs/") !== 0)
headName = "gridfs/" + headName;
url = wrapHost(headName + "@" + width + "w", host);
}
// 最后要合法化一下protocol
url = validateProtocol(url);
return url;
}