@linxin666/dsh-ssh 0.2.4 → 0.2.5
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/lib/client.js +18 -5
- package/lib/client.js.map +1 -1
- package/lib/types/client/locales.d.ts +1 -0
- package/package.json +1 -1
- package/src/client/api.ts +16 -2
- package/src/client/locales.ts +2 -0
- package/src/client/panel/HostFormDialog.tsx +6 -0
package/lib/client.js
CHANGED
|
@@ -36,6 +36,16 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
this.name = "SshApiError";
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
+
/** Extract the `.error` message from a JSON error body; undefined when absent. */
|
|
40
|
+
function extractError(text) {
|
|
41
|
+
if (text === "") return void 0;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(text);
|
|
44
|
+
return typeof parsed?.error === "string" ? parsed.error : void 0;
|
|
45
|
+
} catch {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
/** Parse a JSON response or throw an SshApiError. */
|
|
40
50
|
async function readJson(response) {
|
|
41
51
|
let body;
|
|
@@ -159,7 +169,7 @@ window.__ModuleLoader__.load({
|
|
|
159
169
|
method: "POST",
|
|
160
170
|
body: file
|
|
161
171
|
});
|
|
162
|
-
if (!response.ok || response.body === null) throw new SshApiError(`upload failed: HTTP ${response.status}`);
|
|
172
|
+
if (!response.ok || response.body === null) throw new SshApiError(extractError(await response.text().catch(() => "")) ?? `upload failed: HTTP ${response.status}`);
|
|
163
173
|
const reader = response.body.getReader();
|
|
164
174
|
const decoder = new TextDecoder();
|
|
165
175
|
let buffer = "";
|
|
@@ -202,10 +212,7 @@ window.__ModuleLoader__.load({
|
|
|
202
212
|
alias,
|
|
203
213
|
remotePath
|
|
204
214
|
}));
|
|
205
|
-
if (!response.ok || response.body === null) {
|
|
206
|
-
const text = await response.text().catch(() => "");
|
|
207
|
-
throw new SshApiError(text !== "" && text.startsWith("{") ? text : `download failed: HTTP ${response.status}`);
|
|
208
|
-
}
|
|
215
|
+
if (!response.ok || response.body === null) throw new SshApiError(extractError(await response.text().catch(() => "")) ?? `download failed: HTTP ${response.status}`);
|
|
209
216
|
const total = Number(response.headers.get("content-length") ?? "0");
|
|
210
217
|
const disposition = response.headers.get("content-disposition") ?? "";
|
|
211
218
|
const filename = /filename="([^"]+)"/.exec(disposition)?.[1] ?? remotePath.split("/").pop() ?? "download";
|
|
@@ -365,6 +372,7 @@ window.__ModuleLoader__.load({
|
|
|
365
372
|
"form.passphrase": "密钥口令",
|
|
366
373
|
"form.password": "密码",
|
|
367
374
|
"form.passwordHint": "明文保存在 ~/.dsh/dsh-ssh.json(本机私有文件)",
|
|
375
|
+
"form.passwordRequired": "密码认证需要填写密码。",
|
|
368
376
|
"form.proxyJump": "跳板机别名",
|
|
369
377
|
"form.proxyJumpHint": "逗号分隔的本地主机别名,按顺序连接",
|
|
370
378
|
"form.description": "备注",
|
|
@@ -502,6 +510,7 @@ window.__ModuleLoader__.load({
|
|
|
502
510
|
"form.passphrase": "Key passphrase",
|
|
503
511
|
"form.password": "Password",
|
|
504
512
|
"form.passwordHint": "Stored in plaintext in ~/.dsh/dsh-ssh.json (private local file)",
|
|
513
|
+
"form.passwordRequired": "Password auth requires a password.",
|
|
505
514
|
"form.proxyJump": "Jump host aliases",
|
|
506
515
|
"form.proxyJumpHint": "Comma-separated local aliases, chained in order",
|
|
507
516
|
"form.description": "Description",
|
|
@@ -964,6 +973,10 @@ window.__ModuleLoader__.load({
|
|
|
964
973
|
setError(tt("form.portInvalid"));
|
|
965
974
|
return;
|
|
966
975
|
}
|
|
976
|
+
if (editing == null && form.authKind === "password" && form.password === "") {
|
|
977
|
+
setError(tt("form.passwordRequired"));
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
967
980
|
const secretEmpty = form.authKind === "password" ? form.password === "" : form.keyPath.trim() === "";
|
|
968
981
|
const payload = {
|
|
969
982
|
host,
|