xshell 1.0.180 → 1.0.181
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/path.d.ts +2 -2
- package/server.d.ts +5 -3
- package/server.js +10 -4
- package/utils.browser.d.ts +1 -1
- package/utils.d.ts +1 -1
package/package.json
CHANGED
package/path.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare function extname(path: string): string;
|
|
|
55
55
|
/** `/` */
|
|
56
56
|
export declare const sep = "/";
|
|
57
57
|
/** The platform-specific file delimiter. ';' or ':'. */
|
|
58
|
-
export declare const delimiter: "
|
|
58
|
+
export declare const delimiter: ":" | ";";
|
|
59
59
|
/** Returns an object from a path string - the opposite of format().
|
|
60
60
|
@param path path to evaluate.
|
|
61
61
|
@throws {TypeError} if `path` is not a string. */
|
|
@@ -83,7 +83,7 @@ export declare let path: {
|
|
|
83
83
|
basename: typeof basename;
|
|
84
84
|
extname: typeof extname;
|
|
85
85
|
sep: string;
|
|
86
|
-
delimiter: "
|
|
86
|
+
delimiter: ":" | ";";
|
|
87
87
|
parse: typeof parse;
|
|
88
88
|
format: typeof format;
|
|
89
89
|
toNamespacedPath: typeof toNamespacedPath;
|
package/server.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export declare class Server {
|
|
|
117
117
|
)
|
|
118
118
|
return
|
|
119
119
|
} */
|
|
120
|
-
try_send(ctx: Context, fpd_root: string, fp: string, log_404: boolean): Promise<boolean>;
|
|
120
|
+
try_send(ctx: Context, fpd_root: string, fp: string, log_404: boolean, assets_root?: string): Promise<boolean>;
|
|
121
121
|
/** 将 body 设置为 fp 所指文件的 ReadStream
|
|
122
122
|
检查 fp 是否合法,设置对应的 content-type,支持缓存,支持分块下载
|
|
123
123
|
- ctx: Koa.Context
|
|
@@ -125,11 +125,13 @@ export declare class Server {
|
|
|
125
125
|
- options?:
|
|
126
126
|
- root?: 只能访问 root 下面的文件
|
|
127
127
|
- absolute?: `false` 使用绝对路径指定发送的文件
|
|
128
|
-
- download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
|
|
129
|
-
|
|
128
|
+
- download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
|
|
129
|
+
- assets_root?: 替换模板 xxx.template.html 中 {root} 占位符 */
|
|
130
|
+
fsend(ctx: Context, fp: string, { root, absolute, download, assets_root, }?: {
|
|
130
131
|
root?: string;
|
|
131
132
|
absolute?: boolean;
|
|
132
133
|
download?: boolean;
|
|
134
|
+
assets_root?: string;
|
|
133
135
|
}): Promise<string>;
|
|
134
136
|
/** - range: 取值为逗号分割的多个可用端口或端口区间 (不能含有空格,包含区间右值),比如:`8321,8322,8300-8310,11000-11999
|
|
135
137
|
- reverse?: `false` 在 range 内从后往前尝试 */
|
package/server.js
CHANGED
|
@@ -535,14 +535,14 @@ export class Server {
|
|
|
535
535
|
)
|
|
536
536
|
return
|
|
537
537
|
} */
|
|
538
|
-
async try_send(ctx, fpd_root, fp, log_404) {
|
|
538
|
+
async try_send(ctx, fpd_root, fp, log_404, assets_root) {
|
|
539
539
|
const { request: { _path, path, method }, response, } = ctx;
|
|
540
540
|
if (response.body !== undefined || response.status !== 404)
|
|
541
541
|
return true;
|
|
542
542
|
if (method !== 'HEAD' && method !== 'GET')
|
|
543
543
|
return false;
|
|
544
544
|
try {
|
|
545
|
-
await this.fsend(ctx, fp, { root: fpd_root });
|
|
545
|
+
await this.fsend(ctx, fp, { root: fpd_root, assets_root });
|
|
546
546
|
return true;
|
|
547
547
|
}
|
|
548
548
|
catch (error) {
|
|
@@ -564,8 +564,9 @@ export class Server {
|
|
|
564
564
|
- options?:
|
|
565
565
|
- root?: 只能访问 root 下面的文件
|
|
566
566
|
- absolute?: `false` 使用绝对路径指定发送的文件
|
|
567
|
-
- download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
|
|
568
|
-
|
|
567
|
+
- download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
|
|
568
|
+
- assets_root?: 替换模板 xxx.template.html 中 {root} 占位符 */
|
|
569
|
+
async fsend(ctx, fp, { root, absolute, download, assets_root, } = {}) {
|
|
569
570
|
assert(absolute || root?.isdir, t('fsend 必须传 absolute 选项或 root 文件夹'));
|
|
570
571
|
const { request, request: { method } } = ctx;
|
|
571
572
|
let { response } = ctx;
|
|
@@ -624,6 +625,11 @@ export class Server {
|
|
|
624
625
|
// 以上会自动设置 response.body = null
|
|
625
626
|
return fp;
|
|
626
627
|
}
|
|
628
|
+
if (assets_root) {
|
|
629
|
+
response.body = (await fread(fp, { print: false }))
|
|
630
|
+
.replaceAll('{root}', assets_root);
|
|
631
|
+
return fp;
|
|
632
|
+
}
|
|
627
633
|
const range_header = request.headers.range;
|
|
628
634
|
if (range_header)
|
|
629
635
|
try {
|
package/utils.browser.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare function encode(str: string): Uint8Array;
|
|
|
75
75
|
在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
|
|
76
76
|
export declare function decode(buffer: Uint8Array): string;
|
|
77
77
|
/** 字符串字典序比较 */
|
|
78
|
-
export declare function strcmp(l: string, r: string):
|
|
78
|
+
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
79
79
|
/** 比较 1.10.02 这种版本号
|
|
80
80
|
- l, r: 两个版本号字符串
|
|
81
81
|
- loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
|
package/utils.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare function filter_values<TObj extends Record<string, any>>(obj: TOb
|
|
|
42
42
|
/** 忽略对象中的 keys, 返回新对象 */
|
|
43
43
|
export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
|
|
44
44
|
/** 字符串字典序比较 */
|
|
45
|
-
export declare function strcmp(l: string, r: string):
|
|
45
|
+
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
46
46
|
/** 比较 1.10.02 这种版本号
|
|
47
47
|
- l, r: 两个版本号字符串
|
|
48
48
|
- loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
|