From d8b7aae47a0a9bec115c0ee35592bd1d2cd53855 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Wed, 11 Sep 2024 23:33:16 +0800 Subject: [PATCH] fix(route/zhihu): Fix `d_c0` (#16691) Co-authored-by: Tony --- lib/routes/zhihu/utils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/routes/zhihu/utils.ts b/lib/routes/zhihu/utils.ts index 24a4115fac7429..3a41e1131495b5 100644 --- a/lib/routes/zhihu/utils.ts +++ b/lib/routes/zhihu/utils.ts @@ -70,8 +70,12 @@ export const getSignedHeader = async (url: string, apiPath: string) => { // fisrt: get cookie(dc_0) from zhihu.com const dc0 = await cache.tryGet('zhihu:cookies:d_c0', async () => { - const response1 = await ofetch.raw(url); - const zseCk = response1._data.match(/var e="__zse_ck",t=\(typeof __g\.ck == 'string' && __g\.ck\)\|\|"([\w+/=]*?)",_=6048e5;/)?.[1]; + if (getCookieValueByKey('d_c0')) { + return getCookieValueByKey('d_c0'); + } + const response1 = await ofetch.raw('https://static.zhihu.com/zse-ck/v3.js'); + const script = await response1._data.text(); + const zseCk = script.match(/__g\.ck\|\|"([\w+/=\\]*?)",_=630e8;/)?.[1]; const response2 = zseCk ? await ofetch.raw(url, {