wgt-node-utils 0.0.10 → 0.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgt-node-utils",
3
- "version": "0.0.10",
3
+ "version": "0.0.14",
4
4
  "description": "WGT工具类包",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
@@ -29,6 +29,7 @@
29
29
  "eslint-plugin-react": "^7.37.1",
30
30
  "fs": "0.0.1-security",
31
31
  "globals": "^15.11.0",
32
+ "https": "^1.0.0",
32
33
  "path": "^0.12.7",
33
34
  "typescript-eslint": "^8.9.0",
34
35
  "webpack": "^5.95.0",
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const axios = require('axios');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
+ const https = require('https');
4
5
  const lark = require('@larksuiteoapi/node-sdk');
5
6
  class wgtNodeUtils {
6
7
  constructor(appId, appSecret) {
@@ -155,8 +156,8 @@ class wgtNodeUtils {
155
156
  console.log(new Date(), `获取site失败: domain=${hostname}`);
156
157
  } else {
157
158
  siteId = siteData.siteId;
158
- domainMap[hostname] = siteId;
159
- console.log(new Date(), 'domainMap缓存更新', siteId, domainMap);
159
+ this.domainMap[hostname] = siteId;
160
+ console.log(new Date(), 'domainMap缓存更新', siteId, this.domainMap);
160
161
  }
161
162
  resolve(siteId);
162
163
  });
@@ -272,7 +273,7 @@ class wgtNodeUtils {
272
273
  this.fileContents['react-router-dom.min.js'] = fs.readFileSync(path.join(__dirname, `../${buildName}/dist/react-router-dom.min.js`),'utf8');
273
274
 
274
275
  console.log('静态资源列表:');
275
- const f2eFileLoadStatus = Object.keys(fileContents).every((item) => {
276
+ const f2eFileLoadStatus = Object.keys(this.fileContents).every((item) => {
276
277
  const file = this.fileContents[item];
277
278
  console.log(item, ':', file ? file.length : 'null');
278
279
  return file && file.length > 0;
@@ -323,14 +324,14 @@ class wgtNodeUtils {
323
324
  // 发送消息
324
325
  this.client.im.message.create({
325
326
  params: {
326
- receive_id_type: 'chat_id',
327
+ receive_id_type: 'chat_id'
327
328
  },
328
329
  data: {
329
330
  receive_id: 'oc_aba13955509035daa7a799f30b1b3341',
330
331
  msg_type: 'text',
331
332
  content: `{"text":"<b>前端容器node报错</b>\\ncomponents: ${components}\\nenv: ${process.env.ENV}\\nmesssage: ${message}"}`,
332
- uuid: '',
333
- },
333
+ uuid: ''
334
+ }
334
335
  }).then(res => {
335
336
  console.log('消息发送成功:', res);
336
337
  }).catch(err => {
@@ -373,7 +374,7 @@ class wgtNodeUtils {
373
374
  v === null ||
374
375
  (typeof v === 'string' && v.trim() === '') ||
375
376
  (Object.prototype.toString.apply(v) === '[object Object]' && JSON.stringify(v) === '{}') ||
376
- (Array.isArray(v) && v.every(item => isEmpty(item)))
377
+ (Array.isArray(v) && v.every(item => this.isEmptyObj(item)))
377
378
  );
378
379
  }
379
380
  /**
@@ -453,6 +454,35 @@ class wgtNodeUtils {
453
454
  });
454
455
  });
455
456
  }
457
+
458
+ checkDomainAvailability = (url) => {
459
+ return new Promise((resolve, reject) => {
460
+ const { hostname, path } = new URL(url);
461
+ const options = {
462
+ hostname: hostname,
463
+ path: path,
464
+ method: 'GET'
465
+ };
466
+
467
+ const req = https.request(options, (res) => {
468
+ console.log(res.statusCode,'状态码')
469
+ // 如果状态码为 200,则说明域名可访问
470
+ if (res.statusCode === 200) {
471
+ resolve(true);
472
+ } else {
473
+ resolve(false);
474
+ }
475
+ });
476
+
477
+ req.on('error', (error) => {
478
+ // 发生错误,说明域名不可访问
479
+ console.log(error,'错误信息')
480
+ resolve(false);
481
+ });
482
+
483
+ req.end();
484
+ });
485
+ }
456
486
  /**
457
487
  * 游戏详情页面, 游戏资源链接替换
458
488
  * @link 原始游戏链接
@@ -519,7 +549,7 @@ class wgtNodeUtils {
519
549
  cssStr: this.fileContents[cssName],
520
550
  reactStr: this.fileContents['react.production.min.js'],
521
551
  reactDomStr: this.fileContents['react-dom.production.min.js'],
522
- reactRouterStr: this.fileContents['react-router-dom.min.js'],
552
+ reactRouterStr: this.fileContents['react-router-dom.min.js']
523
553
  };
524
554
  // 每次启动服务后仅对第一次失败进行验证
525
555
  if (!this.filesErrorSendStatus) {
package/webpack.config.js CHANGED
@@ -1,6 +1,4 @@
1
- // webpack.config.js
2
1
  const path = require('path');
3
- const webpack = require('webpack');
4
2
  module.exports = {
5
3
  entry: './src/index.js', // 入口文件
6
4
  output: {
@@ -24,9 +22,16 @@ module.exports = {
24
22
  mode: 'production', // 生产模式,优化打包
25
23
  resolve: {
26
24
  fallback: {
27
- fs: false, // 告诉 Webpack 不需要处理 fs 模块
28
25
  crypto: false,
29
26
  querystring: false
30
27
  },
31
28
  },
29
+ externals: {
30
+ // 排除 Node.js 内置模块
31
+ fs: 'commonjs fs', // 这样 Webpack 不会尝试解析 fs,运行时从 Node.js 中加载
32
+ path: 'commonjs path',
33
+ https: 'commonjs https',
34
+ lark: 'commonjs lark'
35
+ // 其他可能的 Node.js 内置模块
36
+ },
32
37
  };