xshell 0.0.32 → 0.0.35
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/file.d.ts +3 -3
- package/file.js +16 -14
- package/file.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/i18n/index.js +2 -2
- package/i18n/index.js.map +1 -1
- package/net.browser.d.ts +73 -0
- package/net.browser.js +159 -1
- package/net.browser.js.map +1 -1
- package/net.d.ts +76 -0
- package/net.js +161 -1
- package/net.js.map +1 -1
- package/package.json +16 -14
- package/prototype.browser.d.ts +33 -19
- package/prototype.browser.js +45 -21
- package/prototype.browser.js.map +1 -1
- package/prototype.d.ts +9 -2
- package/prototype.js +31 -9
- package/prototype.js.map +1 -1
- package/repl.d.ts +2 -2
- package/repl.js +27 -27
- package/repl.js.map +1 -1
- package/server.d.ts +0 -1
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
- package/utils.js.map +1 -1
package/net.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference types="cheerio" />
|
|
3
3
|
import { default as request_lib } from 'request';
|
|
4
4
|
import { default as request_promise } from 'request-promise-native';
|
|
5
|
+
import { WebSocket } from 'ws';
|
|
5
6
|
import { Cookie, MemoryCookieStore } from 'tough-cookie';
|
|
6
7
|
declare module 'tough-cookie' {
|
|
7
8
|
interface MemoryCookieStore {
|
|
@@ -81,3 +82,78 @@ export declare function rpc(func: string, args?: any[], { url, async: _async, ig
|
|
|
81
82
|
ignore?: boolean;
|
|
82
83
|
}): Promise<any>;
|
|
83
84
|
export declare function rpc_curl(func: string, args: any[]): string;
|
|
85
|
+
export declare function connect_websocket(url: string | URL, { protocols, max_payload, // 8 GB
|
|
86
|
+
on_open, on_close, on_error, on_message }: {
|
|
87
|
+
protocols?: string | string[];
|
|
88
|
+
max_payload?: number;
|
|
89
|
+
on_open?(event: any, websocket: WebSocket): any;
|
|
90
|
+
on_close?(event: {
|
|
91
|
+
code: number;
|
|
92
|
+
reason: string;
|
|
93
|
+
}, websocket: WebSocket): any;
|
|
94
|
+
on_error?(event: any, websocket: WebSocket): any;
|
|
95
|
+
on_message(event: {
|
|
96
|
+
data: ArrayBuffer;
|
|
97
|
+
}, websocket: WebSocket): any;
|
|
98
|
+
}): Promise<WebSocket>;
|
|
99
|
+
/** 二进制消息格式
|
|
100
|
+
- json.length (小端序): 4 字节
|
|
101
|
+
- json 数据
|
|
102
|
+
- binary 数据
|
|
103
|
+
*/
|
|
104
|
+
export interface Message<T extends any[] = any[]> {
|
|
105
|
+
/** 本次 rpc 的 id */
|
|
106
|
+
id?: number;
|
|
107
|
+
/** rpc 发起方指定被调用的 function name, 多个相同 id, func 的 message 组成一个请求流 */
|
|
108
|
+
func?: string;
|
|
109
|
+
/** 等待执行,但不要序列化返回 func 的执行结果 (message 中无 args) */
|
|
110
|
+
ignore?: boolean;
|
|
111
|
+
/** 不等待 func 执行,remote 收到后直接确认返回 (message 中 done = true) */
|
|
112
|
+
async?: boolean;
|
|
113
|
+
/** 这个数组里面要么是对应的 JS 参数,要么是 Uint8Array 参数对应的 binary length
|
|
114
|
+
args 可以是:
|
|
115
|
+
- rpc 发起方调用 func 的参数,或者请求流 message 携带的数据
|
|
116
|
+
- 作为结果或者响应流的 message 数据,传给请求发起方
|
|
117
|
+
*/
|
|
118
|
+
args?: T;
|
|
119
|
+
/** bins: 哪几个 arg 是 Uint8Array 类型的,如: [0, 3] */
|
|
120
|
+
bins?: number[];
|
|
121
|
+
/** 被调方执行 func 产生的错误 */
|
|
122
|
+
error?: Error;
|
|
123
|
+
/** 如果请求或者响应是一个流,通过这个 flag 表明是最后一个 message, 并且可以销毁 handler 了 */
|
|
124
|
+
done?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** 通过创建 Remote 对象对 WebSocket RPC 进行抽象
|
|
127
|
+
调用方使用 remote.call 进行调用
|
|
128
|
+
被调方在创建 Remote 对象时传入 funcs 注册处理函数,并使用 Remote.handle 方法处理 WebSocket message
|
|
129
|
+
*/
|
|
130
|
+
export declare class Remote {
|
|
131
|
+
url: string;
|
|
132
|
+
websocket: WebSocket;
|
|
133
|
+
id: number;
|
|
134
|
+
/** 被调方的 message 处理器 */
|
|
135
|
+
funcs: Record<string, (message: Message, websocket?: WebSocket) => void | Promise<void>>;
|
|
136
|
+
/** 调用方发起的 rpc 对应响应的 message 处理器 */
|
|
137
|
+
handlers: ((message: Message) => any)[];
|
|
138
|
+
print: boolean;
|
|
139
|
+
get connected(): boolean;
|
|
140
|
+
static parse<T extends any[] = any[]>(array_buffer: ArrayBuffer): Message<T>;
|
|
141
|
+
static pack({ id, func, ignore, async: _async, done, error, args: _args, }: Message): Uint8Array;
|
|
142
|
+
constructor({ url, funcs, websocket, }?: {
|
|
143
|
+
url?: string;
|
|
144
|
+
funcs?: Remote['funcs'];
|
|
145
|
+
websocket?: WebSocket;
|
|
146
|
+
});
|
|
147
|
+
connect(): Promise<void>;
|
|
148
|
+
disconnect(): void;
|
|
149
|
+
send(message: Message, websocket?: WebSocket): void;
|
|
150
|
+
/** 调用 remote 中的 func, 返回结果由 handler 处理,处理 done message 之后的返回值作为 call 函数的返回值 */
|
|
151
|
+
call<T extends any[] = any[], R = any>(message: Message, handler: (message: Message<T>) => any): Promise<R>;
|
|
152
|
+
/** 处理接收到的 WebSocket message
|
|
153
|
+
1. 被调用方接收 message 并开始处理
|
|
154
|
+
2. 调用方处理 message 响应
|
|
155
|
+
*/
|
|
156
|
+
handle(event: {
|
|
157
|
+
data: ArrayBuffer;
|
|
158
|
+
}, websocket: WebSocket): Promise<void>;
|
|
159
|
+
}
|
package/net.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.cookies = exports.MyProxy = void 0;
|
|
3
|
+
exports.Remote = exports.connect_websocket = exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.cookies = exports.MyProxy = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const request_promise_native_1 = tslib_1.__importDefault(require("request-promise-native"));
|
|
6
6
|
const errors_js_1 = require("request-promise-native/errors.js");
|
|
7
7
|
const promise_retry_1 = tslib_1.__importDefault(require("promise-retry"));
|
|
8
|
+
const ws_1 = require("ws");
|
|
8
9
|
const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
|
|
9
10
|
const cheerio_1 = tslib_1.__importDefault(require("cheerio"));
|
|
10
11
|
const qs_1 = tslib_1.__importDefault(require("qs"));
|
|
@@ -195,6 +196,7 @@ function parse_html(html) {
|
|
|
195
196
|
Object.defineProperty($.prototype, utils_js_1.inspect.custom, {
|
|
196
197
|
configurable: true,
|
|
197
198
|
enumerable: false,
|
|
199
|
+
// @ts-ignore
|
|
198
200
|
value() {
|
|
199
201
|
if (this.length > 1)
|
|
200
202
|
return this.map((index, element) => {
|
|
@@ -262,4 +264,162 @@ function rpc_curl(func, args) {
|
|
|
262
264
|
return cmd;
|
|
263
265
|
}
|
|
264
266
|
exports.rpc_curl = rpc_curl;
|
|
267
|
+
let decoder = new TextDecoder();
|
|
268
|
+
let encoder = new TextEncoder();
|
|
269
|
+
async function connect_websocket(url, { protocols, max_payload = 2 ** 33, // 8 GB
|
|
270
|
+
on_open, on_close, on_error, on_message }) {
|
|
271
|
+
let websocket = new ws_1.WebSocket(url, protocols, { maxPayload: max_payload });
|
|
272
|
+
// https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543
|
|
273
|
+
websocket.binaryType = 'arraybuffer';
|
|
274
|
+
return new Promise((resolve, reject) => {
|
|
275
|
+
websocket.addEventListener('open', async (event) => {
|
|
276
|
+
console.log(`${websocket.url} opened`);
|
|
277
|
+
await on_open?.(event, websocket);
|
|
278
|
+
resolve(websocket);
|
|
279
|
+
});
|
|
280
|
+
websocket.addEventListener('close', event => {
|
|
281
|
+
console.log(`${websocket.url} closed with code = ${event.code}, reason = '${event.reason}'`);
|
|
282
|
+
on_close?.(event, websocket);
|
|
283
|
+
});
|
|
284
|
+
websocket.addEventListener('error', event => {
|
|
285
|
+
const message = `${websocket.url} errored`;
|
|
286
|
+
console.error(message, event);
|
|
287
|
+
on_error?.(event, websocket);
|
|
288
|
+
reject(Object.assign(new Error(message), { event }));
|
|
289
|
+
});
|
|
290
|
+
websocket.addEventListener('message', event => {
|
|
291
|
+
on_message(event, websocket);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
exports.connect_websocket = connect_websocket;
|
|
296
|
+
/** 通过创建 Remote 对象对 WebSocket RPC 进行抽象
|
|
297
|
+
调用方使用 remote.call 进行调用
|
|
298
|
+
被调方在创建 Remote 对象时传入 funcs 注册处理函数,并使用 Remote.handle 方法处理 WebSocket message
|
|
299
|
+
*/
|
|
300
|
+
class Remote {
|
|
301
|
+
constructor({ url, funcs = {}, websocket, } = {}) {
|
|
302
|
+
this.id = 0;
|
|
303
|
+
/** 调用方发起的 rpc 对应响应的 message 处理器 */
|
|
304
|
+
this.handlers = [];
|
|
305
|
+
this.print = false;
|
|
306
|
+
this.url = url;
|
|
307
|
+
this.funcs = funcs;
|
|
308
|
+
this.websocket = websocket;
|
|
309
|
+
}
|
|
310
|
+
get connected() {
|
|
311
|
+
return this.websocket?.readyState === ws_1.WebSocket.OPEN;
|
|
312
|
+
}
|
|
313
|
+
static parse(array_buffer) {
|
|
314
|
+
const buf = new Uint8Array(array_buffer);
|
|
315
|
+
const dv = new DataView(array_buffer);
|
|
316
|
+
const len_json = dv.getUint32(0, true);
|
|
317
|
+
let offset = 4 + len_json;
|
|
318
|
+
let message = JSON.parse(decoder.decode(buf.subarray(4, offset)));
|
|
319
|
+
message.args || (message.args = []);
|
|
320
|
+
if (message.bins) {
|
|
321
|
+
let args = message.args;
|
|
322
|
+
for (const ibin of message.bins) {
|
|
323
|
+
const len_buf = args[ibin];
|
|
324
|
+
args[ibin] = buf.subarray(offset, offset + len_buf);
|
|
325
|
+
offset += len_buf;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return message;
|
|
329
|
+
}
|
|
330
|
+
static pack({ id, func, ignore, async: _async, done, error, args: _args = [], }) {
|
|
331
|
+
let args = [..._args];
|
|
332
|
+
let bins = [];
|
|
333
|
+
let bufs = [];
|
|
334
|
+
for (let i = 0; i < args.length; i++) {
|
|
335
|
+
const arg = args[i];
|
|
336
|
+
if (arg instanceof Uint8Array) {
|
|
337
|
+
bins.push(i);
|
|
338
|
+
bufs.push(arg);
|
|
339
|
+
args[i] = arg.length;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const data_json = {
|
|
343
|
+
id,
|
|
344
|
+
...func ? { func } : {},
|
|
345
|
+
...ignore ? { ignore } : {},
|
|
346
|
+
..._async ? { async: _async } : {},
|
|
347
|
+
...done ? { done } : {},
|
|
348
|
+
...error ? { error } : {},
|
|
349
|
+
...args.length ? { args } : {},
|
|
350
|
+
...bins.length ? { bins } : {},
|
|
351
|
+
};
|
|
352
|
+
const str_json = encoder.encode(JSON.stringify(data_json));
|
|
353
|
+
let dv = new DataView(new ArrayBuffer(4));
|
|
354
|
+
dv.setUint32(0, str_json.length, true);
|
|
355
|
+
return (0, utils_js_1.concat)([
|
|
356
|
+
dv,
|
|
357
|
+
str_json,
|
|
358
|
+
...bufs
|
|
359
|
+
]);
|
|
360
|
+
}
|
|
361
|
+
async connect() {
|
|
362
|
+
this.websocket = await connect_websocket(this.url, {
|
|
363
|
+
on_message: this.handle.bind(this)
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
disconnect() {
|
|
367
|
+
this.websocket?.close();
|
|
368
|
+
this.id = 0;
|
|
369
|
+
this.handlers = [];
|
|
370
|
+
}
|
|
371
|
+
send(message, websocket = this.websocket) {
|
|
372
|
+
if (!('id' in message))
|
|
373
|
+
message.id = this.id;
|
|
374
|
+
websocket.send(Remote.pack(message));
|
|
375
|
+
}
|
|
376
|
+
/** 调用 remote 中的 func, 返回结果由 handler 处理,处理 done message 之后的返回值作为 call 函数的返回值 */
|
|
377
|
+
async call(message, handler) {
|
|
378
|
+
return new Promise((resolve, reject) => {
|
|
379
|
+
this.handlers[this.id] = async (message) => {
|
|
380
|
+
const { error, done } = message;
|
|
381
|
+
if (error) {
|
|
382
|
+
reject(Object.assign(new Error(), error));
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
let result = await handler(message);
|
|
386
|
+
if (done)
|
|
387
|
+
resolve(result);
|
|
388
|
+
};
|
|
389
|
+
this.send(message);
|
|
390
|
+
this.id++;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/** 处理接收到的 WebSocket message
|
|
394
|
+
1. 被调用方接收 message 并开始处理
|
|
395
|
+
2. 调用方处理 message 响应
|
|
396
|
+
*/
|
|
397
|
+
async handle(event, websocket) {
|
|
398
|
+
const message = Remote.parse(event.data);
|
|
399
|
+
const { func, id, done } = message;
|
|
400
|
+
if (this.print)
|
|
401
|
+
console.log(message);
|
|
402
|
+
if (func) // 作为被调方
|
|
403
|
+
try {
|
|
404
|
+
const handler = this.funcs[func] || this.funcs.default;
|
|
405
|
+
if (!handler)
|
|
406
|
+
throw new Error(`找不到 rpc handler: ${func}`);
|
|
407
|
+
await handler(message, websocket);
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
this.send({
|
|
411
|
+
id: message.id,
|
|
412
|
+
error,
|
|
413
|
+
done: true
|
|
414
|
+
}, websocket);
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
else { // 作为发起方
|
|
418
|
+
this.handlers[id](message);
|
|
419
|
+
if (done)
|
|
420
|
+
this.handlers[id] = null;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
exports.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ACrB,IAAY,EACZ,IAAY,EACZ,EAAE,GAAG,GAAG,+BAA+B,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,KAA0D,EAAG;IAE3I,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAEzD,OAAO,YAAY,CAAC,GAAG,EAAE;QACrB,IAAI,EAAE;YACF,IAAI;YACJ,IAAI;YACJ,KAAK,EAAE,MAAM;YACb,MAAM;SACT;KACJ,CAAC,CAAA;AACN,CAAC;AAfD,kBAeC;AAGD,SAAgB,QAAQ,CAAE,IAAY,EAAE,IAAW;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import {\n default as request_lib,\n type OptionsWithUri,\n type OptionsWithUrl\n} from 'request'\n\nimport {\n default as request_promise,\n type FullResponse,\n} from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors.js'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width } from './utils.js'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n // rejectUnauthorized: false,\n \n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(_body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method.toUpperCase()}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAMA,4FAG+B;AAC/B,gEAAgF;AAEhF,0EAAyC;AAEzC,2BAA8B;AAE9B,oEAA8B;AAC9B,8DAA6B;AAC7B,oDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qBAAM,OA2CA;AAlCf,0BAAuB;AAEvB,yCAA0D;AAE1D,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,gCAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG,GAAG,KAAK;QACnC,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,GAAG;gBACH,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;;gBAE9C,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;QAEjD,IAAI,OAAiB,CAAA;QACrB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,I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AC,CAAA;gBAE/C,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;aACpC;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,IAAI,CACL;oBACI,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,KAAK;oBACL,IAAI,EAAE,IAAI;iBACb,EACD,SAAS,CACZ,CAAA;gBACD,MAAM,KAAK,CAAA;aACd;aACA,EAAG,QAAQ;YACZ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YAC1B,IAAI,IAAI;gBACJ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;SAC/B;IACL,CAAC;CACJ;AApND,wBAoNC","sourcesContent":["import {\n default as request_lib,\n type OptionsWithUri,\n type OptionsWithUrl\n} from 'request'\n\nimport {\n default as request_promise,\n type FullResponse,\n} from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors.js'\n\nimport promise_retry from 'promise-retry'\n\nimport { WebSocket } from 'ws'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width, concat } from './utils.js'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n // rejectUnauthorized: false,\n \n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(_body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n // @ts-ignore\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method.toUpperCase()}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n\nlet decoder = new TextDecoder()\n\nlet encoder = new TextEncoder()\n\n\nexport async function connect_websocket (\n url: string | URL,\n {\n protocols,\n max_payload = 2 ** 33, // 8 GB\n on_open,\n on_close,\n on_error,\n on_message\n }: {\n protocols?: string | string[]\n max_payload?: number\n on_open? (event: any, websocket: WebSocket): any\n on_close? (event: { code: number, reason: string }, websocket: WebSocket): any\n on_error? (event: any, websocket: WebSocket): any\n on_message (event: { data: ArrayBuffer }, websocket: WebSocket): any\n }\n) {\n let websocket = new WebSocket(url, protocols, { maxPayload: max_payload })\n \n // https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543\n websocket.binaryType = 'arraybuffer'\n \n return new Promise<WebSocket>((resolve, reject) => {\n websocket.addEventListener('open', async event => {\n console.log(`${websocket.url} opened`)\n \n await on_open?.(event, websocket)\n \n resolve(websocket)\n })\n \n websocket.addEventListener('close', event => {\n console.log(`${websocket.url} closed with code = ${event.code}, reason = '${event.reason}'`)\n on_close?.(event, websocket)\n })\n \n websocket.addEventListener('error', event => {\n const message = `${websocket.url} errored`\n console.error(message, event)\n on_error?.(event, websocket)\n reject(\n Object.assign(\n new Error(message),\n { event }\n )\n )\n })\n \n websocket.addEventListener('message', event => {\n on_message(event as any, websocket)\n })\n })\n}\n\n\n/** 二进制消息格式 \n - json.length (小端序): 4 字节\n - json 数据\n - binary 数据\n*/\nexport interface Message <T extends any[] = any[]> {\n /** 本次 rpc 的 id */\n id?: number\n \n /** rpc 发起方指定被调用的 function name, 多个相同 id, func 的 message 组成一个请求流 */\n func?: string\n \n /** 等待执行,但不要序列化返回 func 的执行结果 (message 中无 args) */\n ignore?: boolean\n \n /** 不等待 func 执行,remote 收到后直接确认返回 (message 中 done = true) */\n async?: boolean\n \n /** 这个数组里面要么是对应的 JS 参数,要么是 Uint8Array 参数对应的 binary length \n args 可以是: \n - rpc 发起方调用 func 的参数,或者请求流 message 携带的数据\n - 作为结果或者响应流的 message 数据,传给请求发起方\n */\n args?: T\n \n /** bins: 哪几个 arg 是 Uint8Array 类型的,如: [0, 3] */\n bins?: number[]\n \n /** 被调方执行 func 产生的错误 */\n error?: Error\n \n /** 如果请求或者响应是一个流,通过这个 flag 表明是最后一个 message, 并且可以销毁 handler 了 */\n done?: boolean\n}\n\n/** 通过创建 Remote 对象对 WebSocket RPC 进行抽象 \n 调用方使用 remote.call 进行调用 \n 被调方在创建 Remote 对象时传入 funcs 注册处理函数,并使用 Remote.handle 方法处理 WebSocket message \n*/\nexport class Remote {\n url: string\n \n websocket: WebSocket\n \n id = 0\n \n /** 被调方的 message 处理器 */\n funcs: Record<\n string, \n (message: Message, websocket?: WebSocket) => void | Promise<void>\n >\n \n /** 调用方发起的 rpc 对应响应的 message 处理器 */\n handlers: ((message: Message) => any)[] = [ ]\n \n print = false\n \n get connected () {\n return this.websocket?.readyState === WebSocket.OPEN\n }\n \n \n static parse <T extends any[] = any[]> (array_buffer: ArrayBuffer) {\n const buf = new Uint8Array(array_buffer as ArrayBuffer)\n const dv = new DataView(array_buffer)\n \n const len_json = dv.getUint32(0, true)\n \n let offset = 4 + len_json\n \n let message: Message<T> = JSON.parse(\n decoder.decode(\n buf.subarray(4, offset)\n )\n )\n \n message.args ||= [ ] as T\n \n if (message.bins) {\n let args = message.args\n \n for (const ibin of message.bins) {\n const len_buf = args[ibin]\n args[ibin] = buf.subarray(offset, offset + len_buf)\n offset += len_buf\n }\n }\n \n return message\n }\n \n \n static pack ({\n id,\n func,\n ignore,\n async: _async,\n done,\n error,\n args: _args = [ ],\n }: Message) {\n let args = [..._args]\n \n let bins: number[] = [ ]\n let bufs: Uint8Array[] = [ ]\n \n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n if (arg instanceof Uint8Array) {\n bins.push(i)\n bufs.push(arg)\n args[i] = arg.length\n }\n }\n \n const data_json = {\n id,\n ... func ? { func } : { },\n ... ignore ? { ignore } : { },\n ... _async ? { async: _async } : { },\n ... done ? { done } : { },\n ... error ? { error } : { },\n ... args.length ? { args } : { },\n ... bins.length ? { bins } : { },\n }\n \n const str_json = encoder.encode(\n JSON.stringify(data_json)\n )\n \n let dv = new DataView(\n new ArrayBuffer(4)\n )\n \n dv.setUint32(0, str_json.length, true)\n \n return concat([\n dv,\n str_json,\n ... bufs\n ])\n }\n \n \n constructor ({\n url,\n funcs = { },\n websocket,\n }: {\n url?: string\n funcs?: Remote['funcs']\n websocket?: WebSocket\n } = { }) {\n this.url = url\n this.funcs = funcs\n this.websocket = websocket\n }\n \n \n async connect () {\n this.websocket = await connect_websocket(this.url, {\n on_message: this.handle.bind(this)\n })\n }\n \n \n disconnect () {\n this.websocket?.close()\n this.id = 0\n this.handlers = [ ]\n }\n \n \n send (message: Message, websocket = this.websocket) {\n if (!('id' in message))\n message.id = this.id\n \n websocket.send(\n Remote.pack(message)\n )\n }\n \n \n /** 调用 remote 中的 func, 返回结果由 handler 处理,处理 done message 之后的返回值作为 call 函数的返回值 */\n async call <T extends any[] = any[], R = any> (\n message: Message,\n handler: (message: Message<T>) => any\n ) {\n return new Promise<R>((resolve, reject) => {\n this.handlers[this.id] = async (message: Message<T>) => {\n const { error, done } = message\n \n if (error) {\n reject(\n Object.assign(\n new Error(),\n error\n )\n )\n return\n }\n \n let result = await handler(message)\n \n if (done)\n resolve(result)\n }\n \n this.send(message)\n \n this.id++\n })\n }\n \n \n /** 处理接收到的 WebSocket message\n 1. 被调用方接收 message 并开始处理\n 2. 调用方处理 message 响应\n */\n async handle (event: { data: ArrayBuffer }, websocket: WebSocket) {\n const message = Remote.parse(event.data)\n const { func, id, done } = message\n \n if (this.print)\n console.log(message)\n \n if (func) // 作为被调方\n try {\n const handler = this.funcs[func] || this.funcs.default\n \n if (!handler)\n throw new Error(`找不到 rpc handler: ${func}`)\n \n await handler(message, websocket)\n } catch (error) {\n this.send(\n {\n id: message.id,\n error,\n done: true\n },\n websocket\n )\n throw error\n }\n else { // 作为发起方\n this.handlers[id](message)\n if (done)\n this.handlers[id] = null\n }\n }\n}\n\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"xshell": "./xshell.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"type": "commonjs",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=17.
|
|
20
|
-
"vscode": ">=1.
|
|
19
|
+
"node": ">=17.6.0",
|
|
20
|
+
"vscode": ">=1.65.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"start": "node --title=xshell --inspect=0.0.0.0:8420 ./xshell.js",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@babel/core": "^7.17.
|
|
69
|
-
"@babel/parser": "^7.17.
|
|
68
|
+
"@babel/core": "^7.17.7",
|
|
69
|
+
"@babel/parser": "^7.17.7",
|
|
70
70
|
"@babel/traverse": "^7.17.3",
|
|
71
|
-
"@koa/cors": "^3.
|
|
71
|
+
"@koa/cors": "^3.2.0",
|
|
72
72
|
"byte-size": "^8.1.0",
|
|
73
73
|
"chalk": "^4.1.2",
|
|
74
74
|
"chardet": "^1.4.0",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"colors": "^1.4.0",
|
|
79
79
|
"commander": "^8.3.0",
|
|
80
80
|
"ejs": "^3.1.6",
|
|
81
|
-
"emoji-regex": "^10.0.
|
|
81
|
+
"emoji-regex": "^10.0.1",
|
|
82
82
|
"fs-extra": "^10.0.1",
|
|
83
83
|
"fs-monkey": "^1.0.3",
|
|
84
84
|
"gulp-sort": "^2.0.0",
|
|
85
85
|
"hash-string": "^1.0.0",
|
|
86
|
-
"i18next": "^21.6.
|
|
86
|
+
"i18next": "^21.6.14",
|
|
87
87
|
"i18next-scanner": "^3.1.0",
|
|
88
88
|
"iconv-lite": "^0.6.3",
|
|
89
89
|
"js-cookie": "^3.0.1",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"promise-retry": "^2.0.1",
|
|
98
98
|
"qs": "^6.10.3",
|
|
99
99
|
"react": "^17.0.2",
|
|
100
|
-
"react-i18next": "^11.15.
|
|
100
|
+
"react-i18next": "^11.15.7",
|
|
101
101
|
"readdir-enhanced": "^6.0.4",
|
|
102
102
|
"request": "^2.88.2",
|
|
103
103
|
"request-promise-native": "^1.0.9",
|
|
@@ -110,7 +110,8 @@
|
|
|
110
110
|
"typescript": "^4.6.2",
|
|
111
111
|
"upath": "^2.0.1",
|
|
112
112
|
"vinyl": "^2.2.1",
|
|
113
|
-
"vinyl-fs": "^3.0.3"
|
|
113
|
+
"vinyl-fs": "^3.0.3",
|
|
114
|
+
"ws": "^8.5.0"
|
|
114
115
|
},
|
|
115
116
|
"devDependencies": {
|
|
116
117
|
"@babel/types": "^7.17.0",
|
|
@@ -125,19 +126,20 @@
|
|
|
125
126
|
"@types/js-cookie": "^3.0.1",
|
|
126
127
|
"@types/koa": "^2.13.4",
|
|
127
128
|
"@types/koa-compress": "^4.0.3",
|
|
128
|
-
"@types/lodash": "^4.14.
|
|
129
|
+
"@types/lodash": "^4.14.180",
|
|
129
130
|
"@types/node": "^17.0.21",
|
|
130
131
|
"@types/promise-retry": "^1.1.3",
|
|
131
132
|
"@types/qs": "^6.9.7",
|
|
132
|
-
"@types/react": "^17.0.
|
|
133
|
+
"@types/react": "^17.0.40",
|
|
133
134
|
"@types/request": "^2.48.8",
|
|
134
135
|
"@types/request-promise-native": "^1.0.18",
|
|
135
136
|
"@types/rimraf": "^3.0.2",
|
|
136
137
|
"@types/stream-buffers": "^3.0.4",
|
|
137
138
|
"@types/tampermonkey": "^4.0.5",
|
|
138
139
|
"@types/vinyl-fs": "^2.4.12",
|
|
139
|
-
"@types/vscode": "^1.
|
|
140
|
+
"@types/vscode": "^1.65.0",
|
|
141
|
+
"@types/ws": "^8.5.3",
|
|
140
142
|
"source-map-loader": "^3.0.1",
|
|
141
|
-
"ts-loader": "^9.2.
|
|
143
|
+
"ts-loader": "^9.2.8"
|
|
142
144
|
}
|
|
143
145
|
}
|
package/prototype.browser.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ declare global {
|
|
|
8
8
|
否则 返回 this
|
|
9
9
|
*/
|
|
10
10
|
truncate(this: string, width: number): string;
|
|
11
|
+
/** pad string to `<width>`
|
|
12
|
+
- character?: `' '`
|
|
13
|
+
- position?: `'right'`
|
|
14
|
+
*/
|
|
11
15
|
pad(this: string, width: number, { character, position }?: {
|
|
12
16
|
character?: string;
|
|
13
17
|
position?: 'left' | 'right';
|
|
@@ -16,8 +20,17 @@ declare global {
|
|
|
16
20
|
character?: string;
|
|
17
21
|
position?: 'left' | 'right';
|
|
18
22
|
}): string;
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
to_regexp(this: string, preservations?: string, flags?: string): RegExp;
|
|
24
|
+
to_bool(this: string): boolean;
|
|
25
|
+
/** string pattern replacement
|
|
26
|
+
- pattern: match part format
|
|
27
|
+
- pattern_: replaced format
|
|
28
|
+
- preservations?: `''` reserved regular expression characters
|
|
29
|
+
- flags?: `''` regexp matching options
|
|
30
|
+
- transformer?: `(name, matched) => matched || ''` placeholder transformer
|
|
31
|
+
- pattern_placeholder?: `/\{.*?\}/g`
|
|
32
|
+
|
|
33
|
+
```ts
|
|
21
34
|
'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt(
|
|
22
35
|
'{dirp}/[Skytree][海贼王][{ en_name: \\w+ }][{ episode: \\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}',
|
|
23
36
|
'g:/acgn/海贼王/{episode} {encoding}.{format}',
|
|
@@ -27,17 +40,9 @@ declare global {
|
|
|
27
40
|
)
|
|
28
41
|
```
|
|
29
42
|
*/
|
|
30
|
-
refmt(this: string, pattern: string, pattern_: string,
|
|
31
|
-
/** `''` 保留的正则表达式字符 */
|
|
32
|
-
preservations?: string,
|
|
33
|
-
/** `''` 正则匹配选项 */
|
|
34
|
-
flags?: string,
|
|
35
|
-
/** `(name, matched) => matched || ''` placeholder transformer */
|
|
36
|
-
transformer?: (name: string, value: string, placeholders: {
|
|
43
|
+
refmt(this: string, pattern: string, pattern_: string, preservations?: string, flags?: string, transformer?: (name: string, value: string, placeholders: {
|
|
37
44
|
[name: string]: string;
|
|
38
|
-
}) => string,
|
|
39
|
-
/** `/\{.*?\}/g` */
|
|
40
|
-
pattern_placeholder?: RegExp): string;
|
|
45
|
+
}) => string, pattern_placeholder?: RegExp): string;
|
|
41
46
|
/** 字符串模式搜索
|
|
42
47
|
```ts
|
|
43
48
|
'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(
|
|
@@ -54,9 +59,7 @@ declare global {
|
|
|
54
59
|
- flags?: `''` 正则匹配选项
|
|
55
60
|
- pattern_placeholder?: `/\{.*?\}/g`
|
|
56
61
|
*/
|
|
57
|
-
find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp):
|
|
58
|
-
[name: string]: string;
|
|
59
|
-
};
|
|
62
|
+
find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp): Record<string, string>;
|
|
60
63
|
/** - type?: `'single'` */
|
|
61
64
|
quote(this: string, type?: keyof typeof quotes | 'psh'): string;
|
|
62
65
|
/** - shape?: `'parenthesis'` */
|
|
@@ -69,6 +72,7 @@ declare global {
|
|
|
69
72
|
如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags
|
|
70
73
|
*/
|
|
71
74
|
rm(this: string, pattern: string | RegExp, flags?: string): string;
|
|
75
|
+
/** Split the string into lines and remove the '' after the last \n */
|
|
72
76
|
split_lines(this: string): string[];
|
|
73
77
|
trim_doc_comment(this: string): string;
|
|
74
78
|
split_indent(this: string): {
|
|
@@ -80,13 +84,17 @@ declare global {
|
|
|
80
84
|
to_backslash(this: string): string;
|
|
81
85
|
}
|
|
82
86
|
interface Date {
|
|
83
|
-
|
|
87
|
+
/** - ms?: `false` show to ms */
|
|
88
|
+
to_str(this: Date, ms?: boolean): string;
|
|
84
89
|
to_date_str(this: Date): string;
|
|
85
|
-
|
|
90
|
+
/** - ms?: `false` show to ms */
|
|
91
|
+
to_time_str(this: Date, ms?: boolean): string;
|
|
86
92
|
}
|
|
87
93
|
interface Number {
|
|
94
|
+
/** 12.4 KB (1 KB = 1024 B) */
|
|
95
|
+
to_fsize_str(this: number, units?: 'iec' | 'metric'): string;
|
|
88
96
|
to_bin_str(this: number): string;
|
|
89
|
-
to_hex_str(this: number): string;
|
|
97
|
+
to_hex_str(this: number, length?: number): string;
|
|
90
98
|
to_oct_str(this: number): string;
|
|
91
99
|
}
|
|
92
100
|
interface Array<T> {
|
|
@@ -103,6 +111,12 @@ declare global {
|
|
|
103
111
|
}): string[];
|
|
104
112
|
join_lines(): string;
|
|
105
113
|
}
|
|
114
|
+
interface BigInt {
|
|
115
|
+
toJSON(this: bigint): string;
|
|
116
|
+
}
|
|
117
|
+
interface Error {
|
|
118
|
+
toJSON(this: Error): string;
|
|
119
|
+
}
|
|
106
120
|
}
|
|
107
121
|
export declare const emoji_regex: RegExp;
|
|
108
122
|
export declare function to_method_property_descriptors(methods: {
|
|
@@ -126,5 +140,5 @@ export declare const brackets: {
|
|
|
126
140
|
readonly fat: readonly ["【", "】"];
|
|
127
141
|
readonly tortoise_shell: readonly ["〔", "〕"];
|
|
128
142
|
};
|
|
129
|
-
export declare function to_json(
|
|
143
|
+
export declare function to_json(obj: any, replacer?: any): string;
|
|
130
144
|
export declare function is_codepoint_fullwidth(codepoint: number): boolean;
|