Skip to content

feat(139): refresh expiring cloud tokens via PC API - #116

Merged
PIKACHUIM merged 7 commits into
OpenListTeam:mainfrom
UcnacDx2:feat/139-refresh-token-pr
Oct 11, 2026
Merged

PIKACHUIM merged 7 commits into
OpenListTeam:mainfrom
UcnacDx2:feat/139-refresh-token-pr

Conversation

@UcnacDx2

Copy link
Copy Markdown
Contributor

Summary

  • Refresh 139 Cloud PC tokens through POST /user/auth/refreshToken when the token enters its final 15 days.
  • Send the verified minimal request headers without cookies and validate the returned token and expiry.
  • Persist refreshed authorization to the storage configuration, keeping in-flight admin updates in sync.
  • Add a test covering the refresh request, cookie omission, response handling, updated authorization, and persistence callback.

Testing

  • Added/updated driver tests in src/backend/drivers/139/driver.test.ts.
  • Tests have not been executed in this environment; CI should verify them.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 04:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 感谢贡献 PR #116!以下是本次代码审查报告。


总体评价 ✅ Approve ⭐⭐⭐⭐

head commit reviewed: fb2fe3927c79c70f7f46f45a70bb5a2ed2cafbad

PR 在正确位置(init() + 每次 request() 前)双重调用 refreshAuthorizationIfNeeded(),避免长驻 Worker isolate 错过刷新窗口;credentials: "omit" 明确拒绝发送 Cookie;回调机制既更新 db.settings 里的持久化 addition,又同步 in-flight 的 storageConfig.addition,防止管理员操作覆盖新 token。整体思路清晰,实现细节完整,测试覆盖了 request shape、Cookie 缺失、credentials: omit、token 格式校验等关键断言。


发现的问题

P1 — REQUEST_TIMEOUT_MS 定义但从未使用

// util.ts
export const REQUEST_TIMEOUT_MS = 20_000

常量已导出,但 refreshAuthorizationIfNeeded() 中的 fetch 调用没有传入 signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),实际上没有超时保护。Cloudflare Workers 的 subrequest 默认超时较长,刷新 API 若无响应会导致该请求挂起直到 Worker CPU 超时,所有后续 API 请求也随之阻塞。

建议修复:

const response = await fetch(
  "https://user-njs.yun.139.com/user/auth/refreshToken",
  {
    method: "POST",
    credentials: "omit",
    headers,
    body: JSON.stringify({ userDomainId }),
    signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
  },
)

P2 — cp_version 硬编码可能过期

cp_version: "8.9.1.20260929",

版本号直接写死,139 Cloud 若在服务端校验该字段,后续可能需要手动更新。建议在注释中标注「此字段与 PowerShell 测试请求对齐,如刷新失败可检查此值」,或改为可覆盖的配置项。


P2 — user_domain_id 缺失时的错误传播路径

refreshAuthorizationIfNeeded() 在缺少 user_domain_id 时 throw,该异常会从 init() 和 request() 两处向上传播。在 request() 里这意味着所有 139 API 调用在 token 接近过期时都会以配置错误失败,且错误消息是英文的 "139 Cloud token is near expiry; configure user_domain_id..."。建议确认上层 Worker 对该异常有友好的中文错误展示,避免用户看到原始英文消息。


测试覆盖确认 ✅

新增测试(driver.test.ts)覆盖了:

  • 刷新请求的 URL 与 body 形状
  • Cookie 头的缺失断言(credentials: "omit")
  • 必要的 x-yun-* 头出现
  • 意外的 x-yun-uni / x-deviceinfo 头不出现
  • addition.authorization 在刷新后被更新
  • onAuthorizationRefresh 回调被调用

覆盖面充分,逻辑验证完整。


🤖 AI 自动审核声明:本评论由 AI 辅助自动化评审生成,重点聚焦功能正确性与安全性;审查不能替代人工判断,最终合并决策请由维护者确认。如发现评审有误,欢迎直接回复。

@PIKACHUIM
PIKACHUIM merged commit ad1e58d into OpenListTeam:main Oct 11, 2026
1 check passed
@UcnacDx2
UcnacDx2 deleted the feat/139-refresh-token-pr branch October 11, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants