xshell 1.0.90 → 1.0.92

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/i18n/instance.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { I18N } from './index.js';
2
- import _dict from './dict.json' assert { type: 'json' };
2
+ import _dict from './dict.json' with { type: 'json' };
3
3
  export let i18n = new I18N(_dict);
4
4
  const { t, language } = i18n;
5
5
  export { t, language };
@@ -213,7 +213,12 @@ export async function scanner(rootdir = path.normalize(process.cwd()), config =
213
213
  /** 生成 stats.json, unmarkeds.md; 打印 untranslated / unmarkeds */
214
214
  function flush(cb) {
215
215
  // ------------ stats.json
216
- this.push(new_vinyl_file('stats.json', Object.fromEntries(Object.entries(stats).map(([l, { translateds, untranslateds }]) => [l, { translateds: Array.from(translateds), untranslateds: Array.from(untranslateds) }]))));
216
+ // this.push(new_vinyl_file('stats.json',
217
+ // Object.fromEntries(
218
+ // Object.entries(stats).map( ([l, { translateds, untranslateds }]) =>
219
+ // [l, { translateds: Array.from(translateds), untranslateds: Array.from(untranslateds) }])
220
+ // )
221
+ // ))
217
222
  // ------------ 打印 cli 统计表
218
223
  const table = new CliTable({
219
224
  head: [
package/net.browser.d.ts CHANGED
@@ -26,6 +26,7 @@ export interface RequestOptions {
26
26
  auth?: BasicAuth | BearerAuth;
27
27
  cookies?: Record<string, string>;
28
28
  cors?: boolean;
29
+ credentials?: RequestCredentials;
29
30
  }
30
31
  export interface RequestRawOptions extends RequestOptions {
31
32
  raw: true;
package/net.browser.js CHANGED
@@ -32,7 +32,7 @@ async function fetch_retry(url, options, timeout, retries = 0, count = 0) {
32
32
  }
33
33
  }
34
34
  export async function request(url, options = {}) {
35
- const { queries, headers: _headers, body, type = 'application/json', encoding, timeout = 5 * 1000, auth, cors, raw = false, full = false, } = options;
35
+ const { queries, headers: _headers, body, type = 'application/json', encoding, timeout = 5 * 1000, auth, cors, raw = false, full = false, credentials = 'include', } = options;
36
36
  let { method, retries, } = options;
37
37
  url = new URL(url, location.href);
38
38
  if (queries)
@@ -69,7 +69,7 @@ export async function request(url, options = {}) {
69
69
  ...method ? { method } : {},
70
70
  keepalive: true,
71
71
  redirect: 'follow',
72
- credentials: 'include',
72
+ credentials,
73
73
  ...cors ? { mode: 'cors' } : {},
74
74
  headers,
75
75
  // --- body
package/net.d.ts CHANGED
@@ -19,7 +19,8 @@ export declare const WebSocketClosing = 2;
19
19
  export declare const WebSocketClosed = 3;
20
20
  export declare enum MyProxy {
21
21
  socks5 = "http://localhost:10080",
22
- whistle = "http://localhost:8899"
22
+ whistle = "http://localhost:8899",
23
+ work = "http://localhost:10090"
23
24
  }
24
25
  export declare const cookies: {
25
26
  store: MemoryCookieStore;
@@ -152,12 +153,13 @@ export declare class WebSocketConnectionError extends Error {
152
153
  - on_close?: 和 websocket 的 'close' 事件不相同,只在正常关闭 (close code 为 1000) 时才调用,否则都会调用 on_error
153
154
  https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes */
154
155
  export declare function connect_websocket(url: string | URL, { protocols, max_payload, // 8 GB
155
- on_message, on_error, on_close }: {
156
+ on_message, on_error, on_close, proxy }: {
156
157
  protocols?: string[];
157
158
  max_payload?: number;
158
159
  on_message(data: ArrayBuffer | string, websocket: WebSocket): any;
159
160
  on_error?(error: WebSocketConnectionError, websocket: WebSocket): any;
160
161
  on_close?(event: CloseEvent, websocket: WebSocket): any;
162
+ proxy?: string;
161
163
  }): Promise<WebSocket>;
162
164
  /** 接收到消息后的处理函数
163
165
  返回值可以是:
package/net.js CHANGED
@@ -11,6 +11,7 @@ export var MyProxy;
11
11
  (function (MyProxy) {
12
12
  MyProxy["socks5"] = "http://localhost:10080";
13
13
  MyProxy["whistle"] = "http://localhost:8899";
14
+ MyProxy["work"] = "http://localhost:10090";
14
15
  })(MyProxy || (MyProxy = {}));
15
16
  // ------------------------------------ fetch, request
16
17
  export const cookies = {
@@ -43,7 +44,7 @@ async function request_retry(url, options, timeout, retries = 0, count = 0) {
43
44
  return await undici_request(url, options);
44
45
  }
45
46
  catch (error) {
46
- if (error.name === 'TimeoutError') {
47
+ if (error.name === 'TimeoutError')
47
48
  if (count < retries) {
48
49
  const duration = 2 ** count;
49
50
  console.log(`${t('等待 {{duration}} 秒后重试 request (已尝试 {{_count}} 次) …', { duration, _count: count + 1 }).yellow} ${url.toString().blue.underline}`);
@@ -52,13 +53,12 @@ async function request_retry(url, options, timeout, retries = 0, count = 0) {
52
53
  }
53
54
  else
54
55
  throw Object.assign(new Error(`request 超时: ${url.toString()}`), { name: 'TimeoutError' });
55
- }
56
56
  else
57
57
  throw error;
58
58
  }
59
59
  }
60
60
  export async function request(url, options = {}) {
61
- const { ProxyAgent, FormData } = await import('undici');
61
+ const { ProxyAgent: UndiciProxyAgent, FormData } = await import('undici');
62
62
  const { Cookie } = await import('tough-cookie');
63
63
  await cookies.init();
64
64
  const { queries, headers: _headers, body, type = 'application/json', timeout = 5 * 1000, auth, cookies: _cookies, raw = false, full = false, redirect = 'follow', } = options;
@@ -116,7 +116,7 @@ export async function request(url, options = {}) {
116
116
  if (proxy) {
117
117
  if (proxy === true)
118
118
  proxy = MyProxy.socks5;
119
- return proxy_agents[proxy] ??= new ProxyAgent({ uri: proxy });
119
+ return proxy_agents[proxy] ??= new UndiciProxyAgent({ uri: proxy });
120
120
  }
121
121
  })(),
122
122
  // todo: 强制手动处理重定向,来正确处理 cookie ?
@@ -369,6 +369,7 @@ export class WebSocketConnectionError extends Error {
369
369
  }
370
370
  }
371
371
  }
372
+ let websocket_proxy_agents = {};
372
373
  /** 连接 websocket url, 设置各种事件监听器。在 open 事件后 resolve, 返回 websocket
373
374
  遇到 error 时会创建 WebSocketConnectionError:
374
375
  - reject 掉返回的 promise (若此时未 settle)
@@ -386,12 +387,16 @@ export class WebSocketConnectionError extends Error {
386
387
  - on_close?: 和 websocket 的 'close' 事件不相同,只在正常关闭 (close code 为 1000) 时才调用,否则都会调用 on_error
387
388
  https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes */
388
389
  export async function connect_websocket(url, { protocols, max_payload = 2 ** 33, // 8 GB
389
- on_message, on_error, on_close }) {
390
+ on_message, on_error, on_close, proxy }) {
390
391
  const { WebSocket } = await import('ws');
392
+ const { HttpsProxyAgent } = await import('https-proxy-agent');
391
393
  let websocket = new WebSocket(url, protocols, {
392
394
  maxPayload: max_payload,
393
395
  skipUTF8Validation: true,
394
396
  allowSynchronousEvents: true,
397
+ ...proxy ? {
398
+ agent: websocket_proxy_agents[proxy] ??= new HttpsProxyAgent(proxy)
399
+ } : {}
395
400
  });
396
401
  // https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
397
402
  websocket.binaryType = 'arraybuffer';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.90",
3
+ "version": "1.0.92",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -58,9 +58,9 @@
58
58
  "@babel/traverse": "^7.24.1",
59
59
  "@koa/cors": "^5.0.0",
60
60
  "@types/ws": "^8.5.10",
61
- "@typescript-eslint/eslint-plugin": "^7.6.0",
62
- "@typescript-eslint/parser": "^7.6.0",
63
- "@typescript-eslint/utils": "^7.6.0",
61
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
62
+ "@typescript-eslint/parser": "^7.7.1",
63
+ "@typescript-eslint/utils": "^7.7.1",
64
64
  "ali-oss": "^6.20.0",
65
65
  "archiver": "^7.0.1",
66
66
  "byte-size": "^8.1.1",
@@ -71,31 +71,32 @@
71
71
  "colors": "^1.4.0",
72
72
  "commander": "^12.0.0",
73
73
  "emoji-regex": "^10.3.0",
74
- "eslint": "^9.0.0",
74
+ "eslint": "^9.1.1",
75
75
  "eslint-plugin-import": "^2.29.1",
76
76
  "eslint-plugin-react": "^7.34.1",
77
77
  "gulp-sort": "^2.0.0",
78
78
  "hash-string": "^1.0.0",
79
- "i18next": "^23.11.0",
79
+ "https-proxy-agent": "^7.0.4",
80
+ "i18next": "^23.11.2",
80
81
  "i18next-scanner": "^4.4.0",
81
82
  "js-cookie": "^3.0.5",
82
- "koa": "^2.15.2",
83
+ "koa": "^2.15.3",
83
84
  "koa-compress": "^5.1.1",
84
85
  "lodash": "^4.17.21",
85
86
  "map-stream": "0.0.7",
86
87
  "mime-types": "^2.1.35",
87
88
  "ora": "^8.0.1",
88
89
  "react": "^18.2.0",
89
- "react-i18next": "^14.1.0",
90
+ "react-i18next": "^14.1.1",
90
91
  "react-object-model": "^1.2.3",
91
92
  "resolve-path": "^1.4.0",
92
93
  "strip-ansi": "^7.1.0",
93
94
  "through2": "^4.0.2",
94
95
  "tough-cookie": "^4.1.3",
95
96
  "tslib": "^2.6.2",
96
- "typescript": "^5.4.4",
97
+ "typescript": "^5.4.5",
97
98
  "ua-parser-js": "2.0.0-alpha.2",
98
- "undici": "^6.12.0",
99
+ "undici": "^6.14.1",
99
100
  "vinyl": "^3.0.0",
100
101
  "vinyl-fs": "^4.0.0",
101
102
  "ws": "^8.16.0",
@@ -111,7 +112,7 @@
111
112
  "@types/babel__traverse": "^7.20.5",
112
113
  "@types/byte-size": "^8.1.2",
113
114
  "@types/chardet": "^0.8.3",
114
- "@types/eslint": "^8.56.7",
115
+ "@types/eslint": "^8.56.10",
115
116
  "@types/estree": "^1.0.5",
116
117
  "@types/gulp-sort": "2.0.4",
117
118
  "@types/js-cookie": "^3.0.6",
@@ -119,8 +120,8 @@
119
120
  "@types/koa-compress": "^4.0.6",
120
121
  "@types/lodash": "^4.17.0",
121
122
  "@types/mime-types": "^2.1.4",
122
- "@types/node": "^20.12.5",
123
- "@types/react": "^18.2.75",
123
+ "@types/node": "^20.12.7",
124
+ "@types/react": "^18.2.79",
124
125
  "@types/through2": "^2.0.41",
125
126
  "@types/tough-cookie": "^4.0.5",
126
127
  "@types/ua-parser-js": "^0.7.39",
@@ -130,7 +131,7 @@
130
131
  "pnpm": {
131
132
  "patchedDependencies": {
132
133
  "@types/byte-size@8.1.2": "patches/@types__byte-size@8.1.2.patch",
133
- "koa@2.15.2": "patches/koa@2.15.2.patch"
134
+ "koa@2.15.3": "patches/koa@2.15.3.patch"
134
135
  }
135
136
  }
136
137
  }
package/server.d.ts CHANGED
@@ -87,8 +87,9 @@ export declare class Server {
87
87
  _router(ctx: Context, next: Next): Promise<void>;
88
88
  /** 被子类重写以自定义处理逻辑 */
89
89
  router(ctx: Context): Promise<boolean>;
90
- /** 重定向 ctx 到 url (可以是完整 url 也可以是路径),设置 status code 为 code */
91
- redirect(ctx: Context, url: string, code?: 301 | 302): boolean;
90
+ /** 重定向 ctx 到 url (可以是完整 url 也可以是路径),设置 status code 为 code
91
+ - code: 301 (永久重定向) | 302 (临时重定向) | 307 (非 GET 请求保持原有方法和 body 的临时重定向) */
92
+ redirect(ctx: Context, url: string, code: 301 | 302 | 307): true;
92
93
  logger(ctx: Context): void;
93
94
  process_ua(ctx: Context): string;
94
95
  format_ua(headers: IncomingHttpHeaders | IncomingHttp2Headers): string;
package/server.js CHANGED
@@ -326,8 +326,9 @@ export class Server {
326
326
  async router(ctx) {
327
327
  return false;
328
328
  }
329
- /** 重定向 ctx 到 url (可以是完整 url 也可以是路径),设置 status code 为 code */
330
- redirect(ctx, url, code = 301) {
329
+ /** 重定向 ctx 到 url (可以是完整 url 也可以是路径),设置 status code 为 code
330
+ - code: 301 (永久重定向) | 302 (临时重定向) | 307 (非 GET 请求保持原有方法和 body 的临时重定向) */
331
+ redirect(ctx, url, code) {
331
332
  const { request: { _path } } = ctx;
332
333
  let { response } = ctx;
333
334
  response.redirect(url);
File without changes