fix: repair some zhihu routes (#19183)
This commit is contained in:
@@ -3,6 +3,7 @@ import got from '@/utils/got';
|
||||
import { header } from './utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import cache from '@/utils/cache';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/people/allCollections/:id',
|
||||
@@ -11,7 +12,12 @@ export const route: Route = {
|
||||
example: '/zhihu/people/allCollections/87-44-49-67',
|
||||
parameters: { id: '作者 id,可在用户主页 URL 中找到' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'ZHIHU_COOKIES',
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
@@ -35,6 +41,7 @@ async function handler(ctx) {
|
||||
|
||||
const response = await got(apiPath, {
|
||||
headers: {
|
||||
cookie: config.zhihu.cookies,
|
||||
Referer: `https://www.zhihu.com/people/${id}/collections`,
|
||||
},
|
||||
});
|
||||
@@ -46,6 +53,7 @@ async function handler(ctx) {
|
||||
const firstPageResponse = await got(`https://www.zhihu.com/api/v4/collections/${collection.id}/items?offset=0&limit=20`, {
|
||||
headers: {
|
||||
...header,
|
||||
cookie: config.zhihu.cookies,
|
||||
Referer: `https://www.zhihu.com/collection/${collection.id}`,
|
||||
},
|
||||
});
|
||||
@@ -64,6 +72,7 @@ async function handler(ctx) {
|
||||
const response = await got(`https://www.zhihu.com/api/v4/collections/${collection.id}/items?offset=${offset}&limit=20`, {
|
||||
headers: {
|
||||
...header,
|
||||
cookie: config.zhihu.cookies,
|
||||
Referer: `https://www.zhihu.com/collection/${collection.id}`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { load } from 'cheerio';
|
||||
import { header } from './utils';
|
||||
import { generateData } from './pin/utils';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/collection/:id/:getAll?',
|
||||
@@ -12,7 +13,12 @@ export const route: Route = {
|
||||
example: '/zhihu/collection/26444956',
|
||||
parameters: { id: '收藏夹 id,可在收藏夹页面 URL 中找到', getAll: '获取全部收藏内容,任意值为打开' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'ZHIHU_COOKIES',
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
@@ -39,6 +45,7 @@ async function handler(ctx) {
|
||||
url: `https://www.zhihu.com/api/v4/collections/${id}/items?offset=0&limit=20`,
|
||||
headers: {
|
||||
...header,
|
||||
cookie: config.zhihu.cookies,
|
||||
Referer: `https://www.zhihu.com/collection/${id}`,
|
||||
},
|
||||
});
|
||||
@@ -57,6 +64,7 @@ async function handler(ctx) {
|
||||
url: `https://www.zhihu.com/api/v4/collections/${id}/items?offset=${offset}&limit=20`,
|
||||
headers: {
|
||||
...header,
|
||||
cookie: config.zhihu.cookies,
|
||||
Referer: `https://www.zhihu.com/collection/${id}`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,7 +10,12 @@ export const route: Route = {
|
||||
example: '/zhihu/topic/19828946',
|
||||
parameters: { topicId: '话题 id', isTop: '仅精华,默认为否,其他值为是' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'ZHIHU_COOKIES',
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
@@ -33,10 +38,11 @@ async function handler(ctx) {
|
||||
const link = `https://www.zhihu.com/topic/${topicId}/${isTop ? 'top-answers' : 'newest'}`;
|
||||
|
||||
const topicMeta = await cache.tryGet(`zhihu:topic:${topicId}`, async () => {
|
||||
const { data: response } = await got(`https://www.zhihu.com/api/v4/topics/${topicId}/intro`, {
|
||||
searchParams: {
|
||||
include: 'content.meta.content.photos',
|
||||
},
|
||||
const url = `https://www.zhihu.com/topic/${topicId}`;
|
||||
const apiPath = `/api/v4/topics/${topicId}/intro?include=content.meta.content.photos`;
|
||||
const signedHeader = await getSignedHeader(url, apiPath);
|
||||
const { data: response } = await got('https://www.zhihu.com' + apiPath, {
|
||||
headers: signedHeader,
|
||||
});
|
||||
return response;
|
||||
});
|
||||
|
||||
@@ -10,7 +10,12 @@ export const route: Route = {
|
||||
example: '/zhihu/zhuanlan/googledevelopers',
|
||||
parameters: { id: '专栏 id,可在专栏主页 URL 中找到' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'ZHIHU_COOKIES',
|
||||
description: '',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
@@ -47,7 +52,7 @@ async function handler(ctx) {
|
||||
|
||||
const pinnedRes = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/api/v4/columns/${id}/pinned-items`,
|
||||
url: `https://www.zhihu.com/api/v4/columns/${id}/pinned-items/v2`,
|
||||
headers: {
|
||||
...header,
|
||||
...signedHeader,
|
||||
|
||||
Reference in New Issue
Block a user