Skip to content

「账户余额」卡片在 macOS / Linux 上始终查询失败,返回 余额查询失败,detail 为 无法启动查询进程 #10

Description

@elon-ren

环境

  • 系统:macOS(Darwin)
  • DSH 桌面版(虹灵),Node v24
  • 插件:dsh-usage-stats@1.0.0

根因

lib/index.jsfetchBalance() 通过 subprocess.spawn 调用 curl.exepowershell.exe 查询 https://api.deepseek.com/user/balance。这两个可执行文件是 Windows 专属(macOS 只有不带 .execurl,也没有 powershell.exe),因此在非 Windows 平台 spawn 直接失败,两次尝试都落到「无法启动查询进程」。

修复

改用 Node 原生 fetch(Node 18+ 全局可用,跨平台),去掉对 subprocess / curl.exe / powershell.exe 的依赖,并保留原有错误语义(401 / 超时 / 空响应 / is_available=false)。

const url = 'https://api.deepseek.com/user/balance'
let lastDiag = ''
try {
  const response = await fetch(url, {
    method: 'GET',
    headers: { accept: 'application/json', authorization: 'Bearer ' + key },
    signal: AbortSignal.timeout(30000),
  })
  const body = (await response.text()).trim()
  if (!response.ok) {
    lastDiag = 'HTTP ' + response.status + ': ' + body.slice(0, 200)
  } else if (body.length === 0) {
    lastDiag = 'DeepSeek 接口返回空响应'
  } else {
    const parsed = parseBalance(body)
    if (parsed !== null && parsed.unavailable) {
      const payload = { status: 'unavailable', message: 'DeepSeek 接口返回余额不可用(is_available=false)' }
      balanceCache = { fetchedAt: now, payload }
      return payload
    }
    if (parsed !== null && parsed.currencies.length > 0) {
      const payload = { status: 'ok', currencies: parsed.currencies, fetchedAt: now }
      balanceCache = { fetchedAt: now, payload }
      return payload
    }
    lastDiag = body.slice(0, 300)
  }
} catch (err) {
  lastDiag = err instanceof Error ? (err.name === 'TimeoutError' || err.name === 'AbortError' ? '查询超时(30 秒)' : err.message) : String(err)
}

附完整 patch 文件:dsh-usage-stats-macos-balance.patch(可 git apply)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions