fix(route): zhihu `__zse_ck` (#15707)

This commit is contained in:
Tony 2024-05-25 22:29:42 +08:00 committed by GitHub
parent 532e380a56
commit 94ffb50814
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 2 deletions

View File

@ -62,9 +62,25 @@ 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 response = await ofetch.raw(url);
const response1 = await ofetch.raw(url);
const $ = load(response1._data);
const zseCk = $('script:contains("__zse_ck")')
.text()
.match(/\|\|"(.*?)",.*;document\.cookie/)?.[1];
if (!zseCk) {
throw new Error('Failed to extract `__zse_ck` from page');
}
const dc0 = response.headers
const response2 = await ofetch.raw(url, {
headers: {
cookie: `${response1.headers
.getSetCookie()
.map((s) => s.split(';')[0])
.join('; ')}; __zse_ck=${zseCk}`,
},
});
const dc0 = response2.headers
.getSetCookie()
.find((s) => s.startsWith('d_c0='))
?.split(';')[0];