xshell 1.0.50 → 1.0.51
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 +1 -1
- package/server.d.ts +1 -4
- package/server.js +9 -11
- package/utils.browser.d.ts +2 -0
- package/utils.browser.js +13 -0
- package/utils.d.ts +2 -0
- package/utils.js +13 -0
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -68,10 +68,7 @@ export declare class Server {
|
|
|
68
68
|
format_ua(headers: IncomingHttpHeaders | IncomingHttp2Headers): string;
|
|
69
69
|
proxy(ctx: Context, url: string | URL, headers_?: Record<string, string>): Promise<void>;
|
|
70
70
|
static filter_response_headers(headers: Headers): {};
|
|
71
|
-
try_send(ctx: Context,
|
|
72
|
-
root: string;
|
|
73
|
-
log_404?: boolean;
|
|
74
|
-
}): Promise<boolean>;
|
|
71
|
+
try_send(ctx: Context, fpd_root: string, fp: string, log_404: boolean): Promise<boolean>;
|
|
75
72
|
/** 将 body 设置为 fp 所指文件的 ReadStream
|
|
76
73
|
检查 fp 是否合法,设置对应的 content-type,支持缓存,支持分块下载
|
|
77
74
|
- ctx: Koa.Context
|
package/server.js
CHANGED
|
@@ -308,27 +308,25 @@ export class Server {
|
|
|
308
308
|
headers_[key] = value;
|
|
309
309
|
return headers_;
|
|
310
310
|
}
|
|
311
|
-
async try_send(ctx,
|
|
311
|
+
async try_send(ctx, fpd_root, fp, log_404) {
|
|
312
312
|
const { request: { _path, path, method }, response, } = ctx;
|
|
313
|
-
if (
|
|
313
|
+
if (response.body !== undefined || response.status !== 404)
|
|
314
314
|
return true;
|
|
315
315
|
if (method !== 'HEAD' && method !== 'GET')
|
|
316
316
|
return false;
|
|
317
|
-
function _log_404() {
|
|
318
|
-
let s = `${' '.repeat(11)} ${method.toLowerCase()} 404: ${path}`;
|
|
319
|
-
if (_path !== path)
|
|
320
|
-
s += ` ${_path.bracket()}`;
|
|
321
|
-
console.log(s.red);
|
|
322
|
-
}
|
|
323
317
|
try {
|
|
324
|
-
await this.fsend(ctx, fp, { root });
|
|
318
|
+
await this.fsend(ctx, fp, { root: fpd_root });
|
|
325
319
|
return true;
|
|
326
320
|
}
|
|
327
321
|
catch (error) {
|
|
328
322
|
if (error.status !== 404)
|
|
329
323
|
throw error;
|
|
330
|
-
if (log_404)
|
|
331
|
-
|
|
324
|
+
if (log_404) {
|
|
325
|
+
let s = `${' '.repeat(11)} ${method.toLowerCase()} 404: ${path}`;
|
|
326
|
+
if (_path !== path)
|
|
327
|
+
s += ` ${_path.bracket()}`;
|
|
328
|
+
console.log(s.red);
|
|
329
|
+
}
|
|
332
330
|
return false;
|
|
333
331
|
}
|
|
334
332
|
}
|
package/utils.browser.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export declare class Lock<TResource = void> {
|
|
|
51
51
|
export declare function pause(milliseconds?: number): Promise<void>;
|
|
52
52
|
/** 字符串字典序比较 */
|
|
53
53
|
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
54
|
+
export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;
|
|
55
|
+
export declare function invoke<TReturn = any>(obj: any, funcpath: string, args: any[]): TReturn;
|
|
54
56
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
55
57
|
export declare function concat(arrays: ArrayBufferView[]): Uint8Array;
|
|
56
58
|
/** 时间间隔 (milliseconds) 格式化 */
|
package/utils.browser.js
CHANGED
|
@@ -126,6 +126,19 @@ export function strcmp(l, r) {
|
|
|
126
126
|
return -1;
|
|
127
127
|
return 1;
|
|
128
128
|
}
|
|
129
|
+
export function get(obj, keypath) {
|
|
130
|
+
let obj_ = obj;
|
|
131
|
+
for (const key of keypath.split('.'))
|
|
132
|
+
obj_ = obj_[key];
|
|
133
|
+
return obj_;
|
|
134
|
+
}
|
|
135
|
+
export function invoke(obj, funcpath, args) {
|
|
136
|
+
const paths = funcpath.split('.');
|
|
137
|
+
let obj_ = obj;
|
|
138
|
+
for (let i = 0; i < paths.length - 1; i++)
|
|
139
|
+
obj_ = obj_[paths[i]];
|
|
140
|
+
return obj_[paths.at(-1)].call(obj_, ...args);
|
|
141
|
+
}
|
|
129
142
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
130
143
|
export function concat(arrays) {
|
|
131
144
|
let length = 0;
|
package/utils.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare function unique<T>(iterable: T[] | Iterable<T>, selector?: string
|
|
|
22
22
|
export declare function sort_keys<T>(obj: T): T;
|
|
23
23
|
/** 字符串字典序比较 */
|
|
24
24
|
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
25
|
+
export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;
|
|
26
|
+
export declare function invoke<TReturn = any>(obj: any, funcpath: string, args: any[]): TReturn;
|
|
25
27
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
26
28
|
export declare function concat(arrays: ArrayBufferView[]): Uint8Array;
|
|
27
29
|
export declare function typed_array_to_buffer(view: ArrayBufferView): Buffer;
|
package/utils.js
CHANGED
|
@@ -86,6 +86,19 @@ export function strcmp(l, r) {
|
|
|
86
86
|
return -1;
|
|
87
87
|
return 1;
|
|
88
88
|
}
|
|
89
|
+
export function get(obj, keypath) {
|
|
90
|
+
let obj_ = obj;
|
|
91
|
+
for (const key of keypath.split('.'))
|
|
92
|
+
obj_ = obj_[key];
|
|
93
|
+
return obj_;
|
|
94
|
+
}
|
|
95
|
+
export function invoke(obj, funcpath, args) {
|
|
96
|
+
const paths = funcpath.split('.');
|
|
97
|
+
let obj_ = obj;
|
|
98
|
+
for (let i = 0; i < paths.length - 1; i++)
|
|
99
|
+
obj_ = obj_[paths[i]];
|
|
100
|
+
return obj_[paths.at(-1)].call(obj_, ...args);
|
|
101
|
+
}
|
|
89
102
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
90
103
|
export function concat(arrays) {
|
|
91
104
|
let length = 0;
|