wgt-node-utils 1.2.44 → 1.2.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/index.js +80 -64
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -17,8 +17,8 @@ class wgtNodeUtils {
|
|
|
17
17
|
this.sendFeiShuMessageMap = {};
|
|
18
18
|
// 是否發送错误信息开关
|
|
19
19
|
this.filesErrorSendStatus = false;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// 初始化Lark客户端
|
|
21
|
+
if (appId && appSecret) {
|
|
22
22
|
this.initClient(appId, appSecret);
|
|
23
23
|
} else {
|
|
24
24
|
console.error('Lark客户端初始化失败:未提供appId或appSecret');
|
|
@@ -57,7 +57,7 @@ class wgtNodeUtils {
|
|
|
57
57
|
const cfAndroid = headers['cloudfront-is-android-viewer'];
|
|
58
58
|
const cfTablet = headers['cloudfront-is-tablet-viewer'];
|
|
59
59
|
const cfMobile = headers['cloudfront-is-mobile-viewer'];
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
let device = '';
|
|
62
62
|
if (cfDesktop && cfDesktop === 'true') {
|
|
63
63
|
device = 'PC';
|
|
@@ -71,12 +71,12 @@ class wgtNodeUtils {
|
|
|
71
71
|
if (cfTablet && cfTablet === 'true') {
|
|
72
72
|
device = 'Pad';
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
// 部分手机获取不到是Android还是IOS,统一使用Android
|
|
76
76
|
if (!device && cfMobile && cfMobile === 'true') {
|
|
77
77
|
device = 'Android';
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
if (!device) {
|
|
81
81
|
const system = this.getSystem(headers['user-agent']);
|
|
82
82
|
if (system.isPC) {
|
|
@@ -101,7 +101,7 @@ class wgtNodeUtils {
|
|
|
101
101
|
isPhone: device === 'IOS',
|
|
102
102
|
isTablet: device === 'Pad'
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
// 其它设备均为空的情况下,默认当前设置为pc
|
|
106
106
|
if (!system.isAndroid && !system.isPhone && !system.isTablet) {
|
|
107
107
|
system.isPC = true;
|
|
@@ -116,24 +116,24 @@ class wgtNodeUtils {
|
|
|
116
116
|
*/
|
|
117
117
|
addCommonHeadersInfo = (res) => {
|
|
118
118
|
// 增加头信息Content-Type, 在开启gzip时会用到
|
|
119
|
-
res.setHeader('Content-Type','text/html; charset=utf-8');
|
|
119
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
120
120
|
|
|
121
121
|
// 指定被允许iframe的域名
|
|
122
|
-
res.setHeader('Content-Security-Policy','frame-ancestors https://*.enjoy4fun.com https://*.beesads.com');
|
|
122
|
+
res.setHeader('Content-Security-Policy', 'frame-ancestors https://*.enjoy4fun.com https://*.beesads.com');
|
|
123
123
|
|
|
124
124
|
// 通知浏览器应该只通过 HTTPS 访问该站点,并且以后使用 HTTP 访问该站点的所有尝试都应自动重定向到 HTTPS
|
|
125
|
-
res.setHeader('Strict-Transport-Security','max-age=63072000; includeSubDomains; preload');
|
|
125
|
+
res.setHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload');
|
|
126
126
|
|
|
127
127
|
// 指定客户端一定要遵循在 Content-Type 首部中对 MIME 类型 的设定
|
|
128
|
-
res.setHeader('X-Content-Type-Options','nosniff');
|
|
128
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
129
129
|
|
|
130
130
|
// 针对版本 8 及以上的 Internet Explorer,指示浏览器不要直接在浏览器中打开下载
|
|
131
|
-
res.setHeader('X-Download-Options','noopen');
|
|
131
|
+
res.setHeader('X-Download-Options', 'noopen');
|
|
132
132
|
|
|
133
133
|
// 当前页的主题标记为观察对象
|
|
134
134
|
// Topics API 的目的是为调用者(包括运行脚本的页面上的第三方广告技术或广告提供商)提供页面访问者当前可能感兴趣的粗粒度广告主题。
|
|
135
135
|
// 这些主题将补充上下文来自当前页面的信号可以组合起来以帮助为访问者找到合适的广告。
|
|
136
|
-
res.setHeader('Observe-Browsing-Topics','?1');
|
|
136
|
+
res.setHeader('Observe-Browsing-Topics', '?1');
|
|
137
137
|
}
|
|
138
138
|
/***
|
|
139
139
|
* 获取siteId 通过hostname
|
|
@@ -148,7 +148,7 @@ class wgtNodeUtils {
|
|
|
148
148
|
if (siteId) {
|
|
149
149
|
return resolve(siteId);
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
axios.get(url, { params: { domain: hostname } }).then((res) => {
|
|
153
153
|
let siteData = res.data.data;
|
|
154
154
|
// 如果未获取到数据,使用enjoy4fun.com做为默认数据
|
|
@@ -217,7 +217,7 @@ class wgtNodeUtils {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
|
|
221
221
|
// 通过设备清洗zoneKeyMap
|
|
222
222
|
const zoneKeyList = isMobile ? mobileZoneKeyList : pcZoneKeyList;
|
|
223
223
|
let zoneMapForDevice = {};
|
|
@@ -228,9 +228,9 @@ class wgtNodeUtils {
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
siteData.zoneMap = zoneMapForDevice;
|
|
231
|
-
|
|
231
|
+
|
|
232
232
|
// 处理皮肤字段
|
|
233
|
-
const { icon, logo, title, bgLeftImg, bgRightImg, bgBottomImg, ...otherTheme }
|
|
233
|
+
const { icon, logo, title, bgLeftImg, bgRightImg, bgBottomImg, ...otherTheme } = siteData.theme || {};
|
|
234
234
|
siteData.theme = {
|
|
235
235
|
icon: icon ? `${imgDomain}/site_icon/${icon}` : `/${buildName}/favicon.ico`,
|
|
236
236
|
logo: logo ? `${imgDomain}/site_logo/${logo}` : `/${buildName}/assets/logo-small.svg`,
|
|
@@ -274,9 +274,9 @@ class wgtNodeUtils {
|
|
|
274
274
|
});
|
|
275
275
|
|
|
276
276
|
// 增加preact依赖
|
|
277
|
-
this.fileContents['preact.min.js'] = fs.readFileSync(path.join(dirname, `../${buildName}/dist/preact.min.js`),'utf8');
|
|
277
|
+
this.fileContents['preact.min.js'] = fs.readFileSync(path.join(dirname, `../${buildName}/dist/preact.min.js`), 'utf8');
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
console.log('静态资源列表:');
|
|
280
280
|
|
|
281
281
|
const f2eFileLoadStatus = Object.keys(this.fileContents).every((item) => {
|
|
282
282
|
const file = this.fileContents[item];
|
|
@@ -295,12 +295,12 @@ class wgtNodeUtils {
|
|
|
295
295
|
console.log('静态资源:读取结束');
|
|
296
296
|
});
|
|
297
297
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
298
|
+
/***
|
|
299
|
+
* node启动时将静态资源读取到内存中
|
|
300
|
+
* @appId 打包名称
|
|
301
|
+
* @appSecret 打包版本号
|
|
302
|
+
*
|
|
303
|
+
*/
|
|
304
304
|
initClient = (appId, appSecret) => {
|
|
305
305
|
if (!this.client) {
|
|
306
306
|
this.client = new lark.Client({
|
|
@@ -322,14 +322,14 @@ class wgtNodeUtils {
|
|
|
322
322
|
if (!useSendFeiShu) {
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
// 发送消息
|
|
326
|
+
this.client.im.message.create({
|
|
327
327
|
params: {
|
|
328
328
|
receive_id_type: 'chat_id'
|
|
329
329
|
},
|
|
330
330
|
data: {
|
|
331
331
|
receive_id: receive_id,
|
|
332
|
-
msg_type: 'text',
|
|
332
|
+
msg_type: 'text',
|
|
333
333
|
content: feiShuContent,
|
|
334
334
|
uuid: ''
|
|
335
335
|
}
|
|
@@ -364,7 +364,7 @@ class wgtNodeUtils {
|
|
|
364
364
|
* }
|
|
365
365
|
*
|
|
366
366
|
*/
|
|
367
|
-
appendLog = (message, ENV,
|
|
367
|
+
appendLog = (message, ENV, components, err, options = {}) => {
|
|
368
368
|
const {
|
|
369
369
|
usePageUrl = false,
|
|
370
370
|
req = null,
|
|
@@ -372,7 +372,7 @@ class wgtNodeUtils {
|
|
|
372
372
|
useSendFeiShu = false
|
|
373
373
|
} = options;
|
|
374
374
|
try {
|
|
375
|
-
let
|
|
375
|
+
let feiShuContent = `{"text":"<b>前端容器node报错</b>\\ncomponent: ${components}\\nenv: ${ENV}\\nmesssage: ${message}"}`
|
|
376
376
|
if (usePageUrl && req) {
|
|
377
377
|
const pageUrl = new URL(req.originalUrl, `${req.protocol}://${req.get('host')}`).href;
|
|
378
378
|
feiShuContent = `{"text":"<b>前端容器node报错</b>\\ncomponent: ${components}\\nenv: ${ENV}\\npageUrl: ${decodeURIComponent(pageUrl)}\\nmesssage: ${message}"}`
|
|
@@ -386,7 +386,7 @@ class wgtNodeUtils {
|
|
|
386
386
|
console.error(`${message} [${err.config.method}]: ${err.config.url}`);
|
|
387
387
|
// console.error(`request: {params: ${JSON.stringify(err.config.params)}, data: ${ err.config.data ? JSON.stringify(err.config.data) : ''}}`);
|
|
388
388
|
// console.error(`response: ${JSON.stringify( this.safeStringify(err.response.data))}`);
|
|
389
|
-
|
|
389
|
+
|
|
390
390
|
this.sendFeiShu(feiShuContent, receive_id, useSendFeiShu);
|
|
391
391
|
|
|
392
392
|
} else {
|
|
@@ -402,13 +402,13 @@ class wgtNodeUtils {
|
|
|
402
402
|
safeStringify = (obj) => {
|
|
403
403
|
const seen = new WeakSet();
|
|
404
404
|
return JSON.stringify(obj, (key, value) => {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
405
|
+
if (typeof value === 'object' && value !== null) {
|
|
406
|
+
if (seen.has(value)) {
|
|
407
|
+
return; // 忽略循环引用
|
|
408
|
+
}
|
|
409
|
+
seen.add(value);
|
|
408
410
|
}
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
return value;
|
|
411
|
+
return value;
|
|
412
412
|
});
|
|
413
413
|
}
|
|
414
414
|
/**
|
|
@@ -427,20 +427,36 @@ class wgtNodeUtils {
|
|
|
427
427
|
/**
|
|
428
428
|
* 用于渲染游戏卡列表,清理无用字段
|
|
429
429
|
* @param list 清理数组
|
|
430
|
+
* @param need 需要的字段 [game_id,game_category]
|
|
430
431
|
*/
|
|
431
|
-
clearGameCardListData = (list) => {
|
|
432
|
+
clearGameCardListData = (list, need=[]) => {
|
|
433
|
+
var result = {};
|
|
432
434
|
// 游戏卡片使用到的字段
|
|
433
435
|
return list.map((item = {}) => {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
436
|
+
|
|
437
|
+
if (need.length === 0) {
|
|
438
|
+
return {
|
|
439
|
+
id: item.game_id,
|
|
440
|
+
game_category: item.game_category,
|
|
441
|
+
icon: item.base_icon,
|
|
442
|
+
path: item.game_path,
|
|
443
|
+
name: item.game_name,
|
|
444
|
+
icon_video: item.icon_video,
|
|
445
|
+
new: item.new ? true : undefined // 将false转换为undefined, 用于节省ssr生成的文本长度
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
for (var i of need) {
|
|
449
|
+
result[i] = item[i] ? item[i] : '';
|
|
450
|
+
}
|
|
451
|
+
result.name = item.game_name || "";
|
|
452
|
+
result.id = item.game_id || "";
|
|
453
|
+
result.icon = item.base_icon || "";
|
|
454
|
+
result.path = item.game_path || "";
|
|
455
|
+
return result;
|
|
442
456
|
}
|
|
457
|
+
|
|
443
458
|
});
|
|
459
|
+
|
|
444
460
|
}
|
|
445
461
|
|
|
446
462
|
// 用于渲染游戏详情的数据,清理无用字段
|
|
@@ -460,8 +476,8 @@ class wgtNodeUtils {
|
|
|
460
476
|
let categoryBgColor = '';
|
|
461
477
|
const categorys = game.categorys.map((item = {}) => {
|
|
462
478
|
// 抽取第一个存在背景配置的分类
|
|
463
|
-
if (!categoryBg.bg_left && !categoryBg.bg_right
|
|
464
|
-
const bgImg =
|
|
479
|
+
if (!categoryBg.bg_left && !categoryBg.bg_right && !categoryBg.bg_bottom && item.bg_img) {
|
|
480
|
+
const bgImg = item.bg_img || {};
|
|
465
481
|
categoryBg = {
|
|
466
482
|
bg_left: bgImg.bg_left ? `${imgDomain}/${bgImg.bg_left}` : '',
|
|
467
483
|
bg_right: bgImg.bg_right ? `${imgDomain}/${bgImg.bg_right}` : '',
|
|
@@ -572,9 +588,9 @@ class wgtNodeUtils {
|
|
|
572
588
|
path: path,
|
|
573
589
|
method: 'GET'
|
|
574
590
|
};
|
|
575
|
-
|
|
591
|
+
|
|
576
592
|
const req = https.request(options, (res) => {
|
|
577
|
-
console.log(res.statusCode,'状态码')
|
|
593
|
+
console.log(res.statusCode, '状态码')
|
|
578
594
|
// 如果状态码为 200,则说明域名可访问
|
|
579
595
|
if (res.statusCode === 200) {
|
|
580
596
|
resolve(true);
|
|
@@ -582,13 +598,13 @@ class wgtNodeUtils {
|
|
|
582
598
|
resolve(false);
|
|
583
599
|
}
|
|
584
600
|
});
|
|
585
|
-
|
|
601
|
+
|
|
586
602
|
req.on('error', (error) => {
|
|
587
603
|
// 发生错误,说明域名不可访问
|
|
588
|
-
console.log(error,'错误信息')
|
|
604
|
+
console.log(error, '错误信息')
|
|
589
605
|
resolve(false);
|
|
590
606
|
});
|
|
591
|
-
|
|
607
|
+
|
|
592
608
|
req.end();
|
|
593
609
|
});
|
|
594
610
|
}
|
|
@@ -619,13 +635,13 @@ class wgtNodeUtils {
|
|
|
619
635
|
gameDomain = GAME_DEFAULT_DOMAIN;
|
|
620
636
|
}
|
|
621
637
|
}
|
|
622
|
-
|
|
638
|
+
|
|
623
639
|
// 当前游戏domain 为默认游戏域名
|
|
624
640
|
if (gameDomain === GAME_DEFAULT_DOMAIN) {
|
|
625
|
-
console.log(new Date(), 'gameResourcesMap:存在且等于默认游戏名使用默认link', this.gameResourcesMap,'link', link);
|
|
641
|
+
console.log(new Date(), 'gameResourcesMap:存在且等于默认游戏名使用默认link', this.gameResourcesMap, 'link', link);
|
|
626
642
|
return link;
|
|
627
643
|
}
|
|
628
|
-
|
|
644
|
+
|
|
629
645
|
// 替换游戏链接
|
|
630
646
|
if (ENV.includes('prod') || ENV.includes('qa')) {
|
|
631
647
|
gameLink = link.replace(GAME_DEFAULT_DOMAIN, gameDomain);
|
|
@@ -636,7 +652,7 @@ class wgtNodeUtils {
|
|
|
636
652
|
console.log(error, 'ReplaceGameResourcesError')
|
|
637
653
|
gameLink = link;
|
|
638
654
|
}
|
|
639
|
-
|
|
655
|
+
|
|
640
656
|
return gameLink;
|
|
641
657
|
};
|
|
642
658
|
/**
|
|
@@ -719,7 +735,7 @@ class wgtNodeUtils {
|
|
|
719
735
|
|
|
720
736
|
// 预定义的正则表达式(忽略大小写匹配敏感关键词)
|
|
721
737
|
const regex = /\.(php|env|xml|production|example)/i;
|
|
722
|
-
|
|
738
|
+
// 转为小写后检查是否匹配
|
|
723
739
|
return regex.test(path.toLowerCase());
|
|
724
740
|
}
|
|
725
741
|
|
|
@@ -744,7 +760,7 @@ class wgtNodeUtils {
|
|
|
744
760
|
const hasSpecialChar = /[^a-zA-Z0-9/_-]/;
|
|
745
761
|
|
|
746
762
|
|
|
747
|
-
|
|
763
|
+
// 任意条件满足即为非法路径
|
|
748
764
|
return (
|
|
749
765
|
illegalPatterns.test(path) || // 检测非法文件扩展或关键词
|
|
750
766
|
hasUpperCase.test(path) || // 检测大写字母
|
|
@@ -761,7 +777,7 @@ class wgtNodeUtils {
|
|
|
761
777
|
* @param {boolean} option.useSendFeiShu - 是否需要发送飞书
|
|
762
778
|
* @returns {string} - SDK JS字符串
|
|
763
779
|
*/
|
|
764
|
-
getSdkF2eFiles = async(adsTagHref, ENV, option) => {
|
|
780
|
+
getSdkF2eFiles = async (adsTagHref, ENV, option) => {
|
|
765
781
|
const {
|
|
766
782
|
components = '容器名称',
|
|
767
783
|
receive_id = 'oc_aba13955509035daa7a799f30b1b3341',
|
|
@@ -771,8 +787,8 @@ class wgtNodeUtils {
|
|
|
771
787
|
// // 生产环境使用API_PATH,其他环境使用adsTagHref
|
|
772
788
|
// const sdkFilesPath = ENV === 'prod' ? `${API_PATH}/sdk?kaimen=08E28C7EEED6A1B3F9A80154D75A150B` : adsTagHref;
|
|
773
789
|
// 飞书内容
|
|
774
|
-
const feiShuContent = `{"text":"<b>前端容器node报错</b>\\ncomponent: ${components}\\nenv: ${ENV}\\nmesssage: SDK获取失败"}`;
|
|
775
|
-
|
|
790
|
+
const feiShuContent = `{"text":"<b>前端容器node报错</b>\\ncomponent: ${components}\\nenv: ${ENV}\\nmesssage: SDK获取失败"}`;
|
|
791
|
+
|
|
776
792
|
try {
|
|
777
793
|
const res = await axios.get(adsTagHref);
|
|
778
794
|
return res.data;
|
|
@@ -805,7 +821,7 @@ class wgtNodeUtils {
|
|
|
805
821
|
let languageCode = (acceptLanguage ? acceptLanguage.split(',')[0].split('-')[0].toLowerCase() : LANGUAGE_CODE_LIST[0].code) || (countryCode && countryCode.toLowerCase());
|
|
806
822
|
// 如果都没有,则使用默认的语言代码列表中的第一个语言代码
|
|
807
823
|
return LANGUAGE_CODE_LIST.some(item => item.code === languageCode) ? languageCode : LANGUAGE_CODE_LIST[0].code;
|
|
808
|
-
|
|
824
|
+
|
|
809
825
|
}
|
|
810
826
|
|
|
811
827
|
/**
|
|
@@ -821,7 +837,7 @@ class wgtNodeUtils {
|
|
|
821
837
|
return new Promise((resolve) => {
|
|
822
838
|
axios.get(url).then(res => {
|
|
823
839
|
let siteData;
|
|
824
|
-
|
|
840
|
+
|
|
825
841
|
if (type === 'content') {
|
|
826
842
|
siteData = res.data && res.data.data && res.data.data;
|
|
827
843
|
} else if (type === 'novel') {
|
|
@@ -833,7 +849,7 @@ class wgtNodeUtils {
|
|
|
833
849
|
if (!siteData) {
|
|
834
850
|
siteData = ['en'];
|
|
835
851
|
}
|
|
836
|
-
|
|
852
|
+
|
|
837
853
|
resolve(this.formatLanguageCodeList(siteData));
|
|
838
854
|
}).catch(err => {
|
|
839
855
|
resolve(this.formatLanguageCodeList(['en']));
|