xshell 1.0.40 → 1.0.42
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 +5 -5
- package/path.js +4 -4
- package/prototype.browser.d.ts +5 -1
- package/prototype.browser.js +15 -6
- package/prototype.d.ts +4 -2
- package/prototype.js +4 -0
- package/server.js +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"strip-ansi": "^7.1.0",
|
|
80
80
|
"through2": "^4.0.2",
|
|
81
81
|
"tough-cookie": "^4.1.3",
|
|
82
|
-
"tslib": "^2.6.
|
|
82
|
+
"tslib": "^2.6.1",
|
|
83
83
|
"typescript": "^5.1.6",
|
|
84
84
|
"undici": "^5.22.1",
|
|
85
85
|
"vinyl": "^3.0.0",
|
|
@@ -100,13 +100,13 @@
|
|
|
100
100
|
"@types/mime-types": "^2.1.1",
|
|
101
101
|
"@types/node": "^20.4.4",
|
|
102
102
|
"@types/qs": "^6.9.7",
|
|
103
|
-
"@types/react": "^18.2.
|
|
103
|
+
"@types/react": "^18.2.16",
|
|
104
104
|
"@types/through2": "^2.0.38",
|
|
105
105
|
"@types/tough-cookie": "^4.0.2",
|
|
106
106
|
"@types/vinyl-fs": "^3.0.2",
|
|
107
107
|
"@types/vscode": "^1.80.0",
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
109
|
-
"@typescript-eslint/parser": "^6.
|
|
108
|
+
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
109
|
+
"@typescript-eslint/parser": "^6.2.0",
|
|
110
110
|
"eslint": "^8.45.0",
|
|
111
111
|
"eslint-plugin-react": "^7.33.0",
|
|
112
112
|
"eslint-plugin-xlint": "^1.0.6"
|
package/path.js
CHANGED
|
@@ -4,10 +4,10 @@ export function to_fp(str) {
|
|
|
4
4
|
return str;
|
|
5
5
|
const fp = str.replaceAll('\\', '/');
|
|
6
6
|
// 转换小写盘符开头的路径
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
return fp[1] === ':' && 'a' <= fp[0] && fp[0] <= 'z' ?
|
|
8
|
+
fp[0].toUpperCase() + fp.slice(1)
|
|
9
|
+
:
|
|
10
|
+
fp;
|
|
11
11
|
}
|
|
12
12
|
/** Normalize a string path, reducing '..' and '.' parts.
|
|
13
13
|
When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved.
|
package/prototype.browser.d.ts
CHANGED
|
@@ -78,8 +78,12 @@ declare global {
|
|
|
78
78
|
space(this: string): string;
|
|
79
79
|
/** 等价于 .endsWith('/') */
|
|
80
80
|
isdir: boolean;
|
|
81
|
-
/** 以 `/`
|
|
81
|
+
/** 以 `/` 分割的路径,可能以 / 结尾 */
|
|
82
82
|
fp: string;
|
|
83
|
+
/** 以 `/` 分割的文件夹路径,一定以 / 结尾 */
|
|
84
|
+
fpd: string;
|
|
85
|
+
/** 父文件夹路径 (path.dirname),一定以 `/` 结尾 */
|
|
86
|
+
fdir: string;
|
|
83
87
|
/** 文件名 (path.basename 的结果), 保留结尾的 /,如:
|
|
84
88
|
- D:/0/aaa.txt -> aaa.txt
|
|
85
89
|
- D:/aaa/ -> aaa/ */
|
package/prototype.browser.js
CHANGED
|
@@ -35,6 +35,16 @@ export const brackets = {
|
|
|
35
35
|
fat: ['【', '】'],
|
|
36
36
|
tortoise_shell: ['〔', '〕'],
|
|
37
37
|
};
|
|
38
|
+
function to_fp(str) {
|
|
39
|
+
if (!str)
|
|
40
|
+
return str;
|
|
41
|
+
const fp = str.replaceAll('\\', '/');
|
|
42
|
+
// 转换小写盘符开头的路径
|
|
43
|
+
return fp[1] === ':' && 'a' <= fp[0] && fp[0] <= 'z' ?
|
|
44
|
+
fp[0].toUpperCase() + fp.slice(1)
|
|
45
|
+
:
|
|
46
|
+
fp;
|
|
47
|
+
}
|
|
38
48
|
// ------------------------------------ String.prototype
|
|
39
49
|
Object.defineProperties(String.prototype, {
|
|
40
50
|
...to_getter_property_descriptors({
|
|
@@ -278,14 +288,13 @@ Object.defineProperties(String.prototype, {
|
|
|
278
288
|
return this.endsWith('/');
|
|
279
289
|
},
|
|
280
290
|
fp() {
|
|
291
|
+
return to_fp(this);
|
|
292
|
+
},
|
|
293
|
+
fpd() {
|
|
281
294
|
if (!this)
|
|
282
295
|
return this;
|
|
283
|
-
const fp = this
|
|
284
|
-
|
|
285
|
-
if (fp[1] === ':' && 'a' <= fp[0] && fp[0] <= 'z')
|
|
286
|
-
return fp[0].toUpperCase() + fp.slice(1);
|
|
287
|
-
else
|
|
288
|
-
return fp;
|
|
296
|
+
const fp = to_fp(this);
|
|
297
|
+
return fp.endsWith('/') ? fp : `${fp}/`;
|
|
289
298
|
},
|
|
290
299
|
fdir() {
|
|
291
300
|
const fname = (this.endsWith('/') ? this.slice(0, -1) : this).split('/').at(-1);
|
package/prototype.d.ts
CHANGED
|
@@ -99,9 +99,11 @@ declare global {
|
|
|
99
99
|
space(this: string): string;
|
|
100
100
|
/** 等价于 .endsWith('/') */
|
|
101
101
|
isdir: boolean;
|
|
102
|
-
/** 以 `/`
|
|
102
|
+
/** 以 `/` 分割的路径,可能以 / 结尾 */
|
|
103
103
|
fp: string;
|
|
104
|
-
/**
|
|
104
|
+
/** 以 `/` 分割的文件夹路径,一定以 / 结尾 */
|
|
105
|
+
fpd: string;
|
|
106
|
+
/** 父文件夹路径 (path.dirname),一定以 `/` 结尾 */
|
|
105
107
|
fdir: string;
|
|
106
108
|
/** 文件名 (path.basename 的结果), 保留结尾的 /,如:
|
|
107
109
|
- D:/0/aaa.txt -> aaa.txt
|
package/prototype.js
CHANGED
package/server.js
CHANGED
|
@@ -14,6 +14,7 @@ import KoaCors from '@koa/cors';
|
|
|
14
14
|
import KoaCompress from 'koa-compress';
|
|
15
15
|
import { userAgent as KoaUserAgent } from 'koa-useragent';
|
|
16
16
|
// --- my libs
|
|
17
|
+
import { t } from './i18n/instance.js';
|
|
17
18
|
import { request as _request } from './net.js';
|
|
18
19
|
import { stream_to_buffer, inspect, output_width, assert } from './utils.js';
|
|
19
20
|
import { fstat } from './file.js';
|
|
@@ -306,11 +307,9 @@ export class Server {
|
|
|
306
307
|
- absolute?: `false` 使用绝对路径指定发送的文件
|
|
307
308
|
- download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件 */
|
|
308
309
|
async fsend(ctx, fp, { root, absolute, download, } = {}) {
|
|
309
|
-
assert(root
|
|
310
|
+
assert(absolute || root?.isdir, t('fsend 必须传 absolute 选项或 root 文件夹'));
|
|
310
311
|
const { request } = ctx;
|
|
311
312
|
let { response } = ctx;
|
|
312
|
-
if (!absolute && !root)
|
|
313
|
-
throw new Error('fsend with `!absolute && !root`');
|
|
314
313
|
if (!absolute) {
|
|
315
314
|
if (fp.startsWith(root))
|
|
316
315
|
fp = fp.slice(root.length);
|