xshell 1.2.87 → 1.2.89

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.
Files changed (3) hide show
  1. package/package.json +2 -4
  2. package/server.d.ts +2 -4
  3. package/server.js +0 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.2.87",
3
+ "version": "1.2.89",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -89,7 +89,6 @@
89
89
  "ts-loader": "^9.5.4",
90
90
  "tslib": "^2.8.1",
91
91
  "typescript": "^5.9.2",
92
- "ua-parser-js": "^2.0.5",
93
92
  "undici": "^7.16.0",
94
93
  "webpack": "^5.101.3",
95
94
  "webpack-bundle-analyzer": "^4.10.2",
@@ -104,10 +103,9 @@
104
103
  "@types/koa": "^3.0.0",
105
104
  "@types/koa-compress": "^4.0.6",
106
105
  "@types/mime-types": "^3.0.1",
107
- "@types/node": "^24.3.3",
106
+ "@types/node": "^24.4.0",
108
107
  "@types/react": "^19.1.13",
109
108
  "@types/tough-cookie": "^4.0.5",
110
- "@types/ua-parser-js": "^0.7.39",
111
109
  "@types/vscode": "^1.104.0",
112
110
  "@types/webpack-bundle-analyzer": "^4.7.0"
113
111
  }
package/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type Server as HttpServer, type IncomingHttpHeaders, type IncomingMessage } from 'http';
2
- import { type Http2SecureServer, type IncomingHttpHeaders as IncomingHttp2Headers } from 'http2';
1
+ import { type Server as HttpServer, type IncomingMessage } from 'http';
2
+ import { type Http2SecureServer } from 'http2';
3
3
  import type { Duplex } from 'stream';
4
4
  import type { WebSocketServer } from 'ws';
5
5
  import { default as Koa, type Context, type Next } from 'koa';
@@ -105,8 +105,6 @@ export declare class Server {
105
105
  - code: 301 (永久重定向) | 302 (临时重定向) | 307 (非 GET 请求保持原有方法和 body 的临时重定向) */
106
106
  redirect(ctx: Context, url: string, code: 301 | 302 | 307): true;
107
107
  logger(ctx: Context): void;
108
- process_ua(ctx: Context): string;
109
- format_ua(headers: IncomingHttpHeaders | IncomingHttp2Headers): string;
110
108
  /** 转发请求到其他 http 服务,实现网关的功能
111
109
  - ctx
112
110
  - path_url: 只含 host, path, 不含 queries 的 url, 如 http://localhost:8080/api/get-user
package/server.js CHANGED
@@ -8,7 +8,6 @@ import node_sea from 'node:sea';
8
8
  import { default as Koa } from 'koa';
9
9
  import KoaCors from '@koa/cors';
10
10
  import KoaCompress from 'koa-compress';
11
- import { UAParser } from 'ua-parser-js';
12
11
  import resolve_safely from 'resolve-path';
13
12
  import { contentType as get_content_type } from 'mime-types';
14
13
  // --- my libs
@@ -291,10 +290,6 @@ export class Server {
291
290
  s = s.pad(url_width);
292
291
  // ip
293
292
  s += ` <- ${request.socket.remoteAddress.strip_if_start('::ffff:')}`;
294
- // ua
295
- const ua = this.format_ua(headers);
296
- if (ua)
297
- s += `/${ua}`;
298
293
  console.log(s);
299
294
  }
300
295
  switch (url) {
@@ -431,63 +426,12 @@ export class Server {
431
426
  s = s.pad(url_width);
432
427
  // ip
433
428
  s += ` <- ${ip}`;
434
- // ua
435
- const ua = this.process_ua(ctx);
436
- if (ua)
437
- s += `/${ua}`;
438
429
  // body
439
430
  if (body)
440
431
  s += '\n' + inspect(body);
441
432
  // 打印日志
442
433
  console.log(s);
443
434
  }
444
- process_ua(ctx) {
445
- const { headers, headers: { 'user-agent': ua_str } } = ctx.request;
446
- if (!ua_str)
447
- return '';
448
- ctx.response.set('accept-ch', 'Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, RTT, Device-Memory');
449
- return this.format_ua(headers);
450
- }
451
- format_ua(headers) {
452
- const { rtt, 'device-memory': memory } = headers;
453
- const { device, os, browser } = UAParser(headers).withClientHints();
454
- const vendor = device.vendor?.toLowerCase();
455
- const model = device.model?.toLowerCase();
456
- const osname = os.name?.toLowerCase();
457
- const browser_name = browser.name?.toLowerCase();
458
- let s = '';
459
- if (vendor && vendor !== 'apple')
460
- s += vendor;
461
- if (model && model !== 'k' && model !== 'macintosh') {
462
- if (s)
463
- s += ' ';
464
- s += model.replace('22127rk46c', 'redmi k60 pro');
465
- }
466
- if (osname) {
467
- if (s)
468
- s += '/';
469
- s += osname;
470
- if (os.version)
471
- s += ` ${os.version.split('.')[0].toLowerCase()}`;
472
- }
473
- if (browser_name) {
474
- if (s)
475
- s += '/';
476
- s += browser_name.replace('mobile chrome', 'chrome');
477
- if (browser.version) {
478
- const [major, minor] = browser.version.toLowerCase().split('.');
479
- s += ` ${major}`;
480
- if (minor && minor !== '0')
481
- s += `.${minor}`;
482
- }
483
- }
484
- if (memory) {
485
- s += `/${memory}g`;
486
- if (rtt && rtt !== '0')
487
- s += ` ${rtt}ms`;
488
- }
489
- return s;
490
- }
491
435
  /** 转发请求到其他 http 服务,实现网关的功能
492
436
  - ctx
493
437
  - path_url: 只含 host, path, 不含 queries 的 url, 如 http://localhost:8080/api/get-user