dsh-hello 0.1.1 → 0.1.2
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 +60 -51
- package/lib/index.js +46 -9
- package/lib/index.js.map +3 -3
- package/lib/routes.js +71 -11
- package/lib/routes.js.map +1 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -37,14 +37,18 @@ window.__ModuleLoader__.load({
|
|
|
37
37
|
.dd-title{font-size:18px;font-weight:600;margin:0 0 4px;color:var(--dsw-alias-label-primary)}
|
|
38
38
|
.dd-desc{margin:0;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
39
39
|
.dd-row{display:flex;gap:24px;align-items:center;justify-content:space-between;padding:16px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.22))}
|
|
40
|
+
.dd-rowTop{flex-wrap:wrap;row-gap:10px}
|
|
41
|
+
.dd-rowTop .dd-rowText{flex:1 1 240px}
|
|
42
|
+
.dd-rowTop .dd-control{margin-left:auto}
|
|
43
|
+
.dd-rowHead{border-bottom:none;padding-bottom:0}
|
|
40
44
|
.dd-row:last-child{border-bottom:none}
|
|
41
45
|
.dd-rowText{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
42
46
|
.dd-label{font-size:14px;color:var(--dsw-alias-label-primary)}
|
|
43
|
-
.dd-control{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
|
|
47
|
+
.dd-control{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end;flex-shrink:0}
|
|
44
48
|
.dd-block{display:flex;flex-direction:column;gap:8px;padding:16px 0;border-bottom:0.5px solid var(--dsw-alias-border-l3,rgba(127,127,127,.22))}
|
|
45
49
|
.dd-code{font:600 20px ui-monospace,monospace;letter-spacing:3px;color:var(--dsw-alias-brand-primary,#3d7bfd)}
|
|
46
50
|
.dd-segment{display:inline-flex;gap:2px;padding:2px;border-radius:9px;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
|
|
47
|
-
.dd-segmentButton{height:28px;padding:0 12px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-tertiary,#888);font:inherit;font-size:13px;cursor:pointer}
|
|
51
|
+
.dd-segmentButton{height:28px;padding:0 12px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-tertiary,#888);font:inherit;font-size:13px;cursor:pointer;white-space:nowrap}
|
|
48
52
|
.dd-segmentButton.is-active{background:var(--dsw-alias-surface-primary,#fff);color:var(--dsw-alias-label-primary,#111);box-shadow:0 1px 2px rgba(0,0,0,.12)}
|
|
49
53
|
.dd-countdown{font-size:12px;color:var(--dsw-alias-label-tertiary,#888);white-space:nowrap}
|
|
50
54
|
.dd-modalBackdrop{position:fixed;inset:0;z-index:100;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.35)}
|
|
@@ -86,15 +90,10 @@ window.__ModuleLoader__.load({
|
|
|
86
90
|
nav: 'DSH Hello',
|
|
87
91
|
title: 'DSH Hello',
|
|
88
92
|
pairingCode: '配对码',
|
|
89
|
-
|
|
90
|
-
lockHintOff: '关闭后不再接受新设备配对;已连接的设备不受影响',
|
|
93
|
+
lockMode: '锁定',
|
|
91
94
|
lockHintOn: '已锁定:新设备无法配对,已连接的设备照常使用',
|
|
92
|
-
lockAction: '锁定',
|
|
93
|
-
unlockAction: '解除锁定',
|
|
94
95
|
oneTimeMode: '一次性',
|
|
95
96
|
fixedMode: '永久性',
|
|
96
|
-
oneTimeHint: '一次性码过期后自动换新码',
|
|
97
|
-
fixedHint: '永久码不会过期;建议只在可信网络使用',
|
|
98
97
|
remaining: '剩余 {time}',
|
|
99
98
|
reset: '重置',
|
|
100
99
|
modify: '修改',
|
|
@@ -132,15 +131,10 @@ window.__ModuleLoader__.load({
|
|
|
132
131
|
nav: 'DSH Hello',
|
|
133
132
|
title: 'DSH Hello',
|
|
134
133
|
pairingCode: 'Pairing code',
|
|
135
|
-
|
|
136
|
-
lockHintOff: 'Turn this off to stop accepting new devices; paired devices keep working',
|
|
134
|
+
lockMode: 'Lock',
|
|
137
135
|
lockHintOn: 'Locked: new devices cannot pair, while paired devices keep working',
|
|
138
|
-
lockAction: 'Lock',
|
|
139
|
-
unlockAction: 'Unlock',
|
|
140
136
|
oneTimeMode: 'One-time',
|
|
141
137
|
fixedMode: 'Permanent',
|
|
142
|
-
oneTimeHint: 'A new code is generated when this one expires',
|
|
143
|
-
fixedHint: 'The permanent code never expires; use it only on a trusted network',
|
|
144
138
|
remaining: '{time} left',
|
|
145
139
|
reset: 'Reset',
|
|
146
140
|
modify: 'Change',
|
|
@@ -310,6 +304,21 @@ window.__ModuleLoader__.load({
|
|
|
310
304
|
setDialogError(null)
|
|
311
305
|
setDialog('reset')
|
|
312
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* One three-way switch: Lock, One-time, Permanent. Unlocking restores
|
|
309
|
+
* whichever code mode was in force, so switching from Lock to another
|
|
310
|
+
* mode continues into that mode's dialog when it needs input.
|
|
311
|
+
*/
|
|
312
|
+
const chooseMode = async (next) => {
|
|
313
|
+
if (busy || data === null) return
|
|
314
|
+
if (next === 'lock') {
|
|
315
|
+
if (!locked) await setLocked(true)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
if (locked) await setLocked(false)
|
|
319
|
+
if (next === 'one-time' && fixed) openReset()
|
|
320
|
+
if (next === 'permanent' && !fixed) openPermanent()
|
|
321
|
+
}
|
|
313
322
|
const confirmPermanent = async () => {
|
|
314
323
|
const code = password.trim()
|
|
315
324
|
if (!/^\d{4}$/.test(code)) {
|
|
@@ -398,60 +407,60 @@ window.__ModuleLoader__.load({
|
|
|
398
407
|
h('h2', { className: 'dd-title' }, t('title'))),
|
|
399
408
|
error === null ? null : h('p', { className: 'dd-error' }, error),
|
|
400
409
|
|
|
401
|
-
h('div', { className: 'dd-row' },
|
|
402
|
-
h('div', { className: 'dd-rowText' },
|
|
403
|
-
h('span', { className: 'dd-label' }, t('lockLabel')),
|
|
404
|
-
h('span', { className: 'dd-desc' }, locked ? t('lockHintOn') : t('lockHintOff')),
|
|
405
|
-
),
|
|
406
|
-
h('div', { className: 'dd-control' },
|
|
407
|
-
h(Button, {
|
|
408
|
-
variant: locked ? 'primary' : 'outline',
|
|
409
|
-
size: 'sm',
|
|
410
|
-
disabled: busy || data === null,
|
|
411
|
-
onClick: () => { void setLocked(!locked) },
|
|
412
|
-
}, locked ? t('unlockAction') : t('lockAction')),
|
|
413
|
-
),
|
|
414
|
-
),
|
|
415
|
-
|
|
416
|
-
h('div', { className: 'dd-row' },
|
|
410
|
+
h('div', { className: 'dd-row dd-rowTop dd-rowHead' },
|
|
417
411
|
h('div', { className: 'dd-rowText' },
|
|
418
412
|
h('span', { className: 'dd-label' }, t('pairingCode')),
|
|
419
|
-
h('span', { className: 'dd-desc' }, fixed ? t('fixedHint') : t('oneTimeHint')),
|
|
420
413
|
),
|
|
421
414
|
h('div', { className: 'dd-control' },
|
|
422
415
|
h('div', { className: 'dd-segment' },
|
|
423
416
|
h('button', {
|
|
424
417
|
type: 'button',
|
|
425
|
-
className: 'dd-segmentButton' + (
|
|
418
|
+
className: 'dd-segmentButton' + (locked ? ' is-active' : ''),
|
|
419
|
+
disabled: busy || data === null,
|
|
420
|
+
onClick: () => { void chooseMode('lock') },
|
|
421
|
+
}, t('lockMode')),
|
|
422
|
+
h('button', {
|
|
423
|
+
type: 'button',
|
|
424
|
+
className: 'dd-segmentButton' + (!locked && !fixed ? ' is-active' : ''),
|
|
426
425
|
disabled: busy || data === null,
|
|
427
|
-
onClick: () => {
|
|
426
|
+
onClick: () => { void chooseMode('one-time') },
|
|
428
427
|
}, t('oneTimeMode')),
|
|
429
428
|
h('button', {
|
|
430
429
|
type: 'button',
|
|
431
|
-
className: 'dd-segmentButton' + (fixed ? ' is-active' : ''),
|
|
430
|
+
className: 'dd-segmentButton' + (!locked && fixed ? ' is-active' : ''),
|
|
432
431
|
disabled: busy || data === null,
|
|
433
|
-
onClick: () => {
|
|
432
|
+
onClick: () => { void chooseMode('permanent') },
|
|
434
433
|
}, t('fixedMode')),
|
|
435
434
|
),
|
|
436
|
-
h('span', { className: 'dd-code' }, data?.formatted ?? '…'),
|
|
437
|
-
fixed
|
|
438
|
-
? h(Button, {
|
|
439
|
-
variant: 'outline',
|
|
440
|
-
size: 'sm',
|
|
441
|
-
disabled: busy,
|
|
442
|
-
onClick: openPermanent,
|
|
443
|
-
}, t('modify'))
|
|
444
|
-
: h('span', { className: 'dd-countdown' }, left.length > 0 ? t('remaining', { time: left }) : ''),
|
|
445
435
|
),
|
|
446
436
|
),
|
|
447
437
|
|
|
448
|
-
|
|
449
|
-
h('
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
438
|
+
locked
|
|
439
|
+
? h('div', { className: 'dd-row' },
|
|
440
|
+
h('span', { className: 'dd-desc' }, t('lockHintOn')),
|
|
441
|
+
)
|
|
442
|
+
: [
|
|
443
|
+
h('div', { className: 'dd-row', key: 'code' },
|
|
444
|
+
h('span', { className: 'dd-code' }, data?.formatted ?? '…'),
|
|
445
|
+
h('div', { className: 'dd-control' },
|
|
446
|
+
fixed
|
|
447
|
+
? h(Button, {
|
|
448
|
+
variant: 'outline',
|
|
449
|
+
size: 'sm',
|
|
450
|
+
disabled: busy,
|
|
451
|
+
onClick: openPermanent,
|
|
452
|
+
}, t('modify'))
|
|
453
|
+
: h('span', { className: 'dd-countdown' }, left.length > 0 ? t('remaining', { time: left }) : ''),
|
|
454
|
+
),
|
|
455
|
+
),
|
|
456
|
+
h('div', { className: 'dd-block', key: 'qr' },
|
|
457
|
+
h('span', { className: 'dd-label' }, t('qrTitle')),
|
|
458
|
+
typeof data?.qrSvg === 'string' && data.qrSvg.startsWith('<svg')
|
|
459
|
+
? h('div', { className: 'dd-qr-img', dangerouslySetInnerHTML: { __html: data.qrSvg } })
|
|
460
|
+
: h('span', { className: 'dd-desc' }, t('qrFailed')),
|
|
461
|
+
h('span', { className: 'dd-desc' }, t('qrHint')),
|
|
462
|
+
),
|
|
463
|
+
],
|
|
455
464
|
|
|
456
465
|
h('div', { className: 'dd-block' },
|
|
457
466
|
h('span', { className: 'dd-label' }, t('devices')),
|
package/lib/index.js
CHANGED
|
@@ -7520,28 +7520,65 @@ async function sendBinary(rc, file) {
|
|
|
7520
7520
|
});
|
|
7521
7521
|
}
|
|
7522
7522
|
async function renderQr(text) {
|
|
7523
|
+
const candidates = [];
|
|
7523
7524
|
try {
|
|
7524
7525
|
const mod = await Promise.resolve().then(() => __toESM(require_main(), 1));
|
|
7525
|
-
|
|
7526
|
-
return await new Promise((resolve4) => {
|
|
7527
|
-
;
|
|
7528
|
-
qrcode.generate(text, { small: true }, resolve4);
|
|
7529
|
-
});
|
|
7526
|
+
candidates.push(mod.default, mod.default?.default, mod);
|
|
7530
7527
|
} catch {
|
|
7531
|
-
return null;
|
|
7532
7528
|
}
|
|
7529
|
+
try {
|
|
7530
|
+
const { createRequire: createRequire2 } = await import("node:module");
|
|
7531
|
+
candidates.push(createRequire2(import.meta.url)("qrcode-terminal"));
|
|
7532
|
+
} catch {
|
|
7533
|
+
}
|
|
7534
|
+
for (const candidate of candidates) {
|
|
7535
|
+
const generate = candidate?.generate;
|
|
7536
|
+
if (typeof generate !== "function") continue;
|
|
7537
|
+
try {
|
|
7538
|
+
return await new Promise((resolve4) => {
|
|
7539
|
+
;
|
|
7540
|
+
candidate.generate(text, { small: true }, resolve4);
|
|
7541
|
+
});
|
|
7542
|
+
} catch {
|
|
7543
|
+
continue;
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
return null;
|
|
7533
7547
|
}
|
|
7534
|
-
async function
|
|
7548
|
+
async function loadQrSvgApi() {
|
|
7549
|
+
const isApi = (value) => typeof value === "object" && value !== null && typeof value.toString === "function" && value.toString !== Object.prototype.toString;
|
|
7535
7550
|
try {
|
|
7536
7551
|
const mod = await import("qrcode");
|
|
7537
|
-
const
|
|
7538
|
-
|
|
7552
|
+
for (const candidate of [mod.default, mod.default?.default, mod]) {
|
|
7553
|
+
if (isApi(candidate)) return candidate;
|
|
7554
|
+
}
|
|
7555
|
+
} catch (error) {
|
|
7556
|
+
console.warn("[dsh-hello] could not import qrcode through ESM:", error);
|
|
7557
|
+
}
|
|
7558
|
+
try {
|
|
7559
|
+
const { createRequire: createRequire2 } = await import("node:module");
|
|
7560
|
+
const required = createRequire2(import.meta.url)("qrcode");
|
|
7561
|
+
if (isApi(required)) return required;
|
|
7562
|
+
} catch (error) {
|
|
7563
|
+
console.warn("[dsh-hello] could not require qrcode:", error);
|
|
7564
|
+
}
|
|
7565
|
+
return null;
|
|
7566
|
+
}
|
|
7567
|
+
async function renderQrSvg(text) {
|
|
7568
|
+
const qrcode = await loadQrSvgApi();
|
|
7569
|
+
if (qrcode === null) {
|
|
7570
|
+
console.warn("[dsh-hello] qrcode is unavailable; the admin page will not show a QR code");
|
|
7571
|
+
return null;
|
|
7572
|
+
}
|
|
7573
|
+
try {
|
|
7574
|
+
const svg = await qrcode.toString(text, {
|
|
7539
7575
|
type: "svg",
|
|
7540
7576
|
margin: 1,
|
|
7541
7577
|
width: 320,
|
|
7542
7578
|
errorCorrectionLevel: "M",
|
|
7543
7579
|
color: { dark: "#0b0e14", light: "#ffffff" }
|
|
7544
7580
|
});
|
|
7581
|
+
return typeof svg === "string" && svg.trimStart().startsWith("<svg") ? svg : null;
|
|
7545
7582
|
} catch (error) {
|
|
7546
7583
|
console.warn("[dsh-hello] QR SVG generation failed:", error);
|
|
7547
7584
|
return null;
|