Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (routes/zhihu/utils) getSignedHeader throw error cause request failed and ts type fix #18001

Merged
merged 3 commits into from
Dec 31, 2024

Conversation

unliar
Copy link
Contributor

@unliar unliar commented Dec 28, 2024

Involved Issue / 该 PR 相关 Issue

Close #

Example for the Proposed Route(s) / 路由地址示例

/zhihu/people/activities/tombkeeper
/zhihu/posts/people/frederchen

New RSS Route Checklist / 新 RSS 路由检查表

  • New Route / 新的路由
  • Anti-bot or rate limit / 反爬/频率限制
    • If yes, do your code reflect this sign? / 如果有, 是否有对应的措施?
  • Date and time / 日期和时间
    • Parsed / 可以解析
    • Correct time zone / 时区正确
  • New package added / 添加了新的包
  • Puppeteer

Note / 说明

getSignedHeader 向公共方法缓存方法 cache.tryGet 传入的 getValueFunc 参数抛出异常导致了一些不需要 cookie header 的路由报错。

@github-actions github-actions bot added the Route label Dec 28, 2024
Copy link
Contributor

Successfully generated as following:

http://localhost:1200/zhihu/people/activities/tombkeeper - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>FetchError: [GET] &quot;https://www.zhihu.com/api/v3/moments/tombkeeper/activities?limit=7&amp;desktop=true&quot;: 403 Forbidden
Route: /zhihu/people/activities/:id
Full Route: /zhihu/people/activities/tombkeeper
Node Version: v22.12.0
Git Hash: 009c1949
http://localhost:1200/zhihu/posts/people/frederchen - Failed ❌
HTTPError: Response code 503 (Service Unavailable)

Error Message:<br/>FetchError: [GET] &quot;https://www.zhihu.com/api/v4/members/frederchen?include=allow_message%2Cis_followed%2Cis_following%2Cis_org%2Cis_blocking%2Cemployments%2Canswer_count%2Cfollower_count%2Carticles_count%2Cgender%2Cbadge%5B%3F%28type%3Dbest_answerer%29%5D.topics&quot;: 403 Forbidden
Route: /zhihu/posts/:usertype/:id
Full Route: /zhihu/posts/people/frederchen
Node Version: v22.12.0
Git Hash: 009c1949

@github-actions github-actions bot added the Auto: Route Test Complete Auto route test has finished on given PR label Dec 28, 2024
@dzx-dzx
Copy link
Contributor

dzx-dzx commented Dec 28, 2024

如果部分路由不需要signedHeader,可以直接修改这些路由吧?

activities真的不需要吗?

@unliar
Copy link
Contributor Author

unliar commented Dec 28, 2024

如果部分路由不需要signedHeader,可以直接修改这些路由吧?

activities真的不需要吗?

我的想法是:公用方法 cache.tryGet 里关于获取缓存的操作是没有做 try catch 的,因此 getSignedHeader 作为参数 getValueFunc 获取源数据的方法不应该抛出异常。如果部分路由强制一定要获取到 signedHeader 的 dc0 的值,那么业务里就该验证一下是否取到了值。

我看下了这个代码的逻辑,优先会去取用户自己设置的 cookie 里的 dc0 值,如果有就缓存起来。如果没有就再去自动获取 dc0 的值。

如果访问某些路由遭遇反爬失败了,那么应该自己去设置 cookie 。

当前 activities 我在家宽环境下,直接用我修改后的代码是可以的。

@dzx-dzx
Copy link
Contributor

dzx-dzx commented Dec 28, 2024

如果访问某些路由遭遇反爬失败了,那么应该自己去设置 cookie 。

目前的逻辑正是,如果d_c0没有设定而自动获取也失败了,就抛错以提示加入cookie。

当前 activities 我在家宽环境下,直接用我修改后的代码是可以的。

奇怪,xzse96 没有d_c0应该会计算失败的。

@TonyRL TonyRL merged commit 3f94723 into DIYgod:master Dec 31, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto: Route Test Complete Auto route test has finished on given PR Route
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants