xshell 1.0.111 → 1.0.113

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/index.js CHANGED
@@ -6,7 +6,7 @@ export const LANGUAGES = ['zh', 'en', 'ja', 'ko'];
6
6
  @see https://github.com/ShenHongFei/xshell/tree/master/i18n
7
7
  */
8
8
  export class I18N {
9
- static LANGUAGE_REGEXP = /^(zh|en|ja|jp|ko)$/;
9
+ static LANGUAGE_REGEXP = /^(zh|en|ja|ko)$/;
10
10
  /** (ISO 639-1 标准语言代码) 可能取 zh, en, ja, ko */
11
11
  language;
12
12
  /** hostname shortcuts */
@@ -81,8 +81,7 @@ export class I18N {
81
81
  fallbackLng: {
82
82
  en: ['zh'],
83
83
  ja: ['en', 'zh'],
84
- ko: ['en', 'zh'],
85
- default: ['en', 'zh']
84
+ ko: ['en', 'zh']
86
85
  },
87
86
  // 禁用 : 和 . 作为 seperator
88
87
  keySeparator: false,
package/net.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
- import type { Readable } from 'stream';
3
+ import { type Readable } from 'stream';
4
4
  import type { FormData } from 'undici';
5
5
  import type { WebSocket, CloseEvent, ErrorEvent } from 'ws';
6
6
  import type { Cookie, CookieJar, MemoryCookieStore } from 'tough-cookie';
@@ -20,7 +20,7 @@ export declare const WebSocketClosed = 3;
20
20
  export declare enum MyProxy {
21
21
  socks5 = "http://localhost:10080",
22
22
  whistle = "http://localhost:8899",
23
- work = "http://127.0.0.1:10090"
23
+ work = "http://localhost:10090"
24
24
  }
25
25
  export declare const cookies: {
26
26
  store: MemoryCookieStore;
@@ -51,7 +51,7 @@ export interface RequestOptions {
51
51
  method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
52
52
  queries?: Record<string, any>;
53
53
  headers?: Record<string, string>;
54
- body?: string | Record<string, any> | Uint8Array | URLSearchParams | FormData;
54
+ body?: string | Record<string, any> | Uint8Array | URLSearchParams | FormData | Readable;
55
55
  type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
56
56
  proxy?: boolean | MyProxy | string;
57
57
  encoding?: Encoding | 'binary';
@@ -60,6 +60,7 @@ export interface RequestOptions {
60
60
  auth?: BasicAuth | BearerAuth;
61
61
  cookies?: Record<string, string>;
62
62
  redirect?: RequestRedirect;
63
+ decode?: boolean;
63
64
  }
64
65
  export interface RequestFullOptions extends RequestOptions {
65
66
  full: true;
@@ -97,7 +98,8 @@ export interface RequestError extends Error {
97
98
  - auth?: BasicAuth | BearerAuth
98
99
  - cookies?: 需要额外添加到请求的 cookies, 默认情况下携带了 MemoryCookieStore 中保存的之前 http 响应中的 cookies
99
100
  - raw?: `false` 传入后返回整个 response (RawResponse),body 为 Readable
100
- - full?: `false` 传入后返回整个 response (FullResponse),body 根据 encoding 对应为 string 或 Buffer */
101
+ - full?: `false` 传入后返回整个 response (FullResponse),body 根据 encoding 对应为 string 或 Buffer
102
+ - decode?: 根据 content-encoding: br 等解码压缩后的 response.body */
101
103
  export declare function request(url: string | URL): Promise<string>;
102
104
  export declare function request(url: string | URL, options: RequestRawOptions): Promise<RawResponse>;
103
105
  export declare function request(url: string | URL, options: RequestFullOptions & {
package/net.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import zlib from 'zlib';
2
2
  import { buffer as stream_to_buffer, text as stream_to_text } from 'stream/consumers';
3
+ import { isReadable } from 'stream';
3
4
  import { t } from './i18n/instance.js';
4
5
  import './prototype.js';
5
6
  import { inspect, concat, assert, genid, delay, Lock, encode, decode, pipe_with_error, map_values, unique } from './utils.js';
@@ -11,7 +12,7 @@ export var MyProxy;
11
12
  (function (MyProxy) {
12
13
  MyProxy["socks5"] = "http://localhost:10080";
13
14
  MyProxy["whistle"] = "http://localhost:8899";
14
- MyProxy["work"] = "http://127.0.0.1:10090";
15
+ MyProxy["work"] = "http://localhost:10090";
15
16
  })(MyProxy || (MyProxy = {}));
16
17
  // ------------------------------------ fetch, request
17
18
  export const cookies = {
@@ -62,7 +63,7 @@ export async function request(url, options = {}) {
62
63
  const { ProxyAgent: UndiciProxyAgent, FormData } = await import('undici');
63
64
  const { Cookie } = await import('tough-cookie');
64
65
  await cookies.init();
65
- const { queries, headers: _headers, body, type = 'application/json', timeout = 5 * 1000, auth, cookies: _cookies, raw = false, full = false, redirect = 'follow', } = options;
66
+ const { queries, headers: _headers, body, type = 'application/json', timeout = 5 * 1000, auth, cookies: _cookies, raw = false, full = false, redirect = 'follow', decode = true, } = options;
66
67
  let { method, retries, encoding, proxy, } = options;
67
68
  url = new URL(url);
68
69
  if (queries)
@@ -133,6 +134,8 @@ export async function request(url, options = {}) {
133
134
  body: (() => {
134
135
  if (body === undefined)
135
136
  return;
137
+ if (typeof body?.read === 'function' && isReadable(body))
138
+ return body;
136
139
  switch (type) {
137
140
  case 'application/json': // 可能的类型 string | Record<string, any> | Uint8Array
138
141
  if (typeof body === 'string')
@@ -169,7 +172,7 @@ export async function request(url, options = {}) {
169
172
  // UndiciResponse.body 没有自动根据 content-encoding 来解码,这里手动处理并替换 body 为解码后的 stream
170
173
  let body = _body;
171
174
  const content_encoding = headers['content-encoding']?.trim().toLowerCase();
172
- if (content_encoding) {
175
+ if (decode && content_encoding) {
173
176
  assert(!content_encoding.includes(','));
174
177
  switch (content_encoding) {
175
178
  case 'gzip':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.111",
3
+ "version": "1.0.113",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -99,7 +99,7 @@
99
99
  "tslib": "^2.6.2",
100
100
  "typescript": "^5.4.5",
101
101
  "ua-parser-js": "^2.0.0-beta.2",
102
- "undici": "^6.18.1",
102
+ "undici": "^6.18.2",
103
103
  "vinyl": "^3.0.0",
104
104
  "vinyl-fs": "^4.0.0",
105
105
  "ws": "^8.17.0"
@@ -118,7 +118,7 @@
118
118
  "@types/koa-compress": "^4.0.6",
119
119
  "@types/lodash": "^4.17.4",
120
120
  "@types/mime-types": "^2.1.4",
121
- "@types/node": "^20.12.12",
121
+ "@types/node": "^20.12.13",
122
122
  "@types/react": "^18.3.3",
123
123
  "@types/through2": "^2.0.41",
124
124
  "@types/tough-cookie": "^4.0.5",
@@ -63,7 +63,7 @@ export declare function encode(str: string): Uint8Array;
63
63
  在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
64
64
  export declare function decode(buffer: Uint8Array): string;
65
65
  /** 字符串字典序比较 */
66
- export declare function strcmp(l: string, r: string): 0 | 1 | -1;
66
+ export declare function strcmp(l: string, r: string): 1 | 0 | -1;
67
67
  /** 比较 1.10.02 这种版本号 */
68
68
  export declare function vercmp(l: string, r: string): number;
69
69
  export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;
package/utils.d.ts CHANGED
@@ -39,7 +39,7 @@ export declare function filter_values<TObj extends Record<string, any>>(obj: TOb
39
39
  /** 忽略对象中的 keys, 返回新对象 */
40
40
  export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
41
41
  /** 字符串字典序比较 */
42
- export declare function strcmp(l: string, r: string): 0 | 1 | -1;
42
+ export declare function strcmp(l: string, r: string): 1 | 0 | -1;
43
43
  /** 比较 1.10.02 这种版本号 */
44
44
  export declare function vercmp(l: string, r: string): number;
45
45
  export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;