@whyshu/argent 0.2.7 → 0.2.8
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/src/tunnel.mjs +24 -9
package/package.json
CHANGED
package/src/tunnel.mjs
CHANGED
|
@@ -530,18 +530,33 @@ export function startTunnel(options = {}) {
|
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
// ── dsh 准入 cookie(仅内存;401/403 重换一次)──────────────────────────
|
|
533
|
+
// dsh 准入 token 的三条来源(优先级:env → 启动脚本写出的 token 文件 → 本机 /api/argent-state/access)
|
|
534
|
+
// 为什么需要文件来源:`/api/argent-state/access` 由 argent-core 插件提供;单插件(@whyshu/argent)装配下
|
|
535
|
+
// 该端点 401 ⇒ 隧道拿不到 token ⇒ App 侧表现为 access-unavailable(2026-11-07 实测)。
|
|
536
|
+
const readTokenFile = () => {
|
|
537
|
+
try {
|
|
538
|
+
const t = readFileSync(join(String(options.dataDir || ''), 'dsh-web.token'), 'utf8').trim()
|
|
539
|
+
return t || ''
|
|
540
|
+
} catch { return '' }
|
|
541
|
+
}
|
|
533
542
|
const acquireCookie = async ({ refresh = false } = {}) => {
|
|
534
543
|
if (!refresh && dsh.cookie) return dsh.cookie
|
|
535
|
-
let access
|
|
536
|
-
try {
|
|
537
|
-
access = await fetchImpl(`${dshBase}${DSH_ACCESS_PATH}`, {
|
|
538
|
-
headers: { accept: 'application/json' },
|
|
539
|
-
signal: AbortSignal.timeout(5000),
|
|
540
|
-
})
|
|
541
|
-
} catch { throw err('access-unreachable') }
|
|
542
544
|
let body = null
|
|
543
|
-
|
|
544
|
-
|
|
545
|
+
const envToken = String(env.ARGENT_DSH_TOKEN || '').trim()
|
|
546
|
+
const fileToken = envToken ? '' : readTokenFile()
|
|
547
|
+
if (envToken || fileToken) {
|
|
548
|
+
body = { ok: true, token: envToken || fileToken }
|
|
549
|
+
} else {
|
|
550
|
+
let access
|
|
551
|
+
try {
|
|
552
|
+
access = await fetchImpl(`${dshBase}${DSH_ACCESS_PATH}`, {
|
|
553
|
+
headers: { accept: 'application/json' },
|
|
554
|
+
signal: AbortSignal.timeout(5000),
|
|
555
|
+
})
|
|
556
|
+
} catch { throw err('access-unreachable') }
|
|
557
|
+
try { body = await access.json() } catch { body = null }
|
|
558
|
+
if (!access.ok || !body || body.ok !== true || !body.token) throw err('access-unavailable', `HTTP ${access.status}`)
|
|
559
|
+
}
|
|
545
560
|
let res
|
|
546
561
|
try {
|
|
547
562
|
res = await fetchImpl(`${dshBase}/?token=${encodeURIComponent(String(body.token))}`, {
|