wgt-node-utils
v1.2.68
Published
WGT工具类包
Downloads
759
Readme
wgt-node-utils
发布流程
1、设置npm发布仓库地址为Nexus的地址
npm set http://172.30.10.160:8081/nexus/repository/wgt/ 2、运行npm打包,最终引用的文件为dist 文件夹
npm run build3、 发布包整体
npm publish --registry http://172.30.10.160:8081/nexus/repository/wgt/ wgt node端 公共函数库 使用方法
项目安装脚本
npm install wgt-node-utils --registry http://172.30.10.160:8081/nexus/repository/npm-group工具库使用
const wgtNodeUtils = require('wgt-node-utils');
wgtNodeUtils.getSiteByHostname(siteIdPath, req.hostname, DEFAULT_SITE_ID)工具函数说明
getSystem 获取系统信息
使用
wgtNodeUtils.getSystem(userAgent)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | userAgent | string | 设备的Ua信息 | 是 | -- |
getCloudFrontDevice 获取系统信息
使用
wgtNodeUtils.getCloudFrontDevice(headers)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | headers | object | CDN 返回的req.headers 对象 | 是 | -- |
getCloudFrontSystem // 获取cloud front传回的设备信息
使用
wgtNodeUtils.getCloudFrontSystem(device)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | device | string | 回传设备信息 | 是 | -- |
addCommonHeadersInfo // 通用头信息添加
使用
wgtNodeUtils.addCommonHeadersInfo(res)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | res | object | node端 响应 header 对象 | 是 | -- |
getSiteByHostname // 获取siteId 通过hostname
使用方法
await wgtNodeUtils.getSiteByHostname(url, hostname, defaultSiteId)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | url | string | 获取siteID接口地址 | 是 | -- | | hostname | string | 网站解析域名 | 是 | -- | | defaultSiteId | string | 网站默认siteID | 是 | -- |
readF2eFiles // node启动时将静态资源读取到内存中
使用方法
await wgtNodeUtils.readF2eFiles(buildName, version, dirname, useGlobal)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------|------|-----| | buildName | string | 项目打包名称 | 是 | -- | | version | string | 项目版本号 | 是 | -- | | dirname | string | 项目绝对地址 | 是 | -- | | useGlobal | boolean | 是否需要读取global.css文件 | 否 | false |
getMainDomainByHostname // 获取主域名
使用
wgtNodeUtils.getMainDomainByHostname(hostname)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------|------|-----| | hostname | string | 网站地址 | 是 | -- |
appendLog // node启动时将静态资源读取到内存中
使用方法
await wgtNodeUtils.appendLog(message, ENV, components, err)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | message | string | 错误信息 | 是 | -- | | err | string || object | 错误类型 | 是 | -- | | ENV | string | 环境变量 | 是 | -- | | components | string | 项目名称 | 是 | -- | | option | object | 扩展对象 | 否 | false | --| | option.usePageUrl | boolean | 是否需要页面url (err为对象才可以使用是否发送pageUrl) | 否 | -- | | option.useSendFeiShu | boolean | 是否需要发送飞书 | 否 | false | | option.req | object | node端页面请求体 | 否 | null | | option.receive_id | string | 发送飞书群ID | 否 | oc_aba13955509035daa7a799f30b1b3341 |
isEmptyObj // 验证是否空对象
使用
wgtNodeUtils.isEmptyObj(object)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | object | object | 验证对象 | 是 | -- |
clearGameCardListData // 用于渲染游戏卡列表,清理无用字段
使用
wgtNodeUtils.clearGameCardListData(list)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | list | array | 所需要清理的list item返回格式 | 是 | -- |
返回格式
return {
game_category: item.game_category,
id: item.game_id,
icon: item.base_icon,
path: item.game_path,
name: item.game_name,
icon_video: item.icon_video || null,
new: item.new ? true : undefined // 将false转换为undefined, 用于节省ssr生成的文本长度
}clearGameData // 用于渲染游戏详情的数据,清理无用字段
使用
wgtNodeUtils.clearGameData(list)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | list | array | 所需要清理的list | 是 | -- |
返回格式
return {
id: item.id,
path: item.path,
icon: item.base_icon,
name: item.name
};clearCategoryListData // 用于渲染类型卡片列表,清理无用字段
使用
wgtNodeUtils.clearCategoryListData(list)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | list | array | 所需要清理的list | 是 | -- |
返回格式
return {
id: item.id,
path: item.path,
icon: item.base_icon,
name: item.name
};clearWalkThroughVideoListData // 用于渲染演练视频卡片的数据,清理无用字段
使用
wgtNodeUtils.clearWalkThroughVideoListData(list)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | list | array | 所需要清理的list | 是 | -- |
返回格式
return {
game_name: item.game_name,
game_path: item.game_path,
thumbnail: item.thumbnail,
video_id: item.video_id,
duration: item.duration
};getLanguageList // 获取网站语言列表
使用
wgtNodeUtils.getLanguageList(url)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | hostname | string | 网站语言请求地址 | 是 | -- |
checkDomainAvailability // 监测域名是否可用 以状态返回200为准 返回 boolean
使用
wgtNodeUtils.checkDomainAvailability(url)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | url | string | 需要检查域名地址 | 是 | -- |
ReplaceGameResources // 游戏详情页面, 游戏资源链接替换 返回字符串
使用
await wgtNodeUtils.ReplaceGameResources(link, hostName, ENV)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | link | string | 需要检查域名地址 | 是 | -- | | hostName | string | 需要检查域名地址 | 是 | -- | | ENV | string | 需要检查域名地址 | 是 | -- |
getModelF2eFiles // 获取前端静态资源列表
使用
await wgtNodeUtils.getModelF2eFiles(pageName, isMobile)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | pageName | string | 静态页面文件名称 | 是 | -- | | isMobile | boolean | 是否为手机设备 | 是 | -- |
getSdkF2eFiles // 获取sdk静态资源
使用
await wgtNodeUtils.getSdkF2eFiles(API_PATH, adsTagHref, ENV)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | API_PATH | string | 项目API路径 | 是 | -- | | adsTagHref | string | SDK静态资源桶路径 | 是 | -- | | ENV | string | 项目环境变量 | 是 | -- | | option | object | 项目环境变量 | 否 | -- | | option.components | string | 项目模版容器名称 | 否 | 容器名称 | | option.receive_id | string | 发送飞书ID | 否 | oc_aba13955509035daa7a799f30b1b3341 | | option.useSendFeiShu | boolean | 项目环境变量 | 否 | false |
getSiteLanguage // 获取站点语言列表
使用
await wgtNodeUtils.getSiteLanguage(url, type)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | url | string | 请求url | 是 | -- | | url | string | 网站模版类型 novel:小说 content: 咨询 | 是 | -- |
getCloudFrontViewerCountry // 获取国家code || 用户浏览器设备语言
使用
await wgtNodeUtils.getCloudFrontViewerCountry(req)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | req | Object | node 请求req | 是 | -- |
getSearchSiteSystem // 获取search模版的设备
使用
await wgtNodeUtils.getSearchSiteSystem(searchSiteSystem)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | req.searchSiteSystem | string | search模版回传的当前展示pc还是手机端 只有两个值 pc 或者mobile | 是 | -- |
getGetTemplateConfiguration // 获取当前模版配置 是否是search模版调用
使用
wgtNodeUtils.getGetTemplateConfiguration(req)参数说明:
|参数 | 类型 | 说明 | 是否必传 | 默认值 | |---------|--------------|-----------------------------------------------------------------------------|------|-----| | req | Object | node端req 请求体 | 是 | -- |
返回格式
return {
isSearchSite,
hostname,
system,
};