Skip to content

Commit

Permalink
feat(route/zhihu): Allow to set login cookies (#16281)
Browse files Browse the repository at this point in the history
* feat(route/zhihu): Allow to set login cookies

* Update the description.

* Update utils.ts
  • Loading branch information
dzx-dzx authored Jul 29, 2024
1 parent ad5e52b commit 774839b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/routes/zhihu/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '知乎',
url: 'www.zhihu.com',
description: `:::tip
自2024年7月,未登录状态下大部分路由[无法获取全文](https://github.com/DIYgod/RSSHub/issues/16260)。若有需要请在登陆知乎后寻找并添加包含\`z_c0\`的Cookies至环境变量\`ZHIHU_COOKIES\`。
:::`,
};
8 changes: 7 additions & 1 deletion lib/routes/zhihu/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import g_encrypt from './execlib/x-zse-96-v3';
import md5 from '@/utils/md5';
import { config } from '@/config';

export const header = {
'x-api-version': '3.0.91',
Expand Down Expand Up @@ -93,8 +94,13 @@ export const getSignedHeader = async (url: string, apiPath: string) => {
const xzse93 = '101_3_3.0';
const f = `${xzse93}+${apiPath}+${dc0}`;
const xzse96 = '2.0_' + g_encrypt(md5(f));

const zc0 = config.zhihu.cookies
?.split(';')
.find((e) => e.includes('z_c0'))
?.slice('z_c0='.length);
return {
cookie: `d_c0=${dc0}`,
cookie: `d_c0=${dc0}${zc0 ? `;z_c0=${zc0}` : ''}`,
'x-zse-96': xzse96,
'x-app-za': 'OS=Web',
'x-zse-93': xzse93,
Expand Down

0 comments on commit 774839b

Please sign in to comment.