From 70c4fe93d7fb0b8b5c24acd91f01300974dabc6d Mon Sep 17 00:00:00 2001
From: JimenezLi <75196426+JimenezLi@users.noreply.github.com>
Date: Sat, 18 May 2024 19:05:10 +0800
Subject: [PATCH] fix(route): fix utils for xhu (#15623)
---
lib/routes/zhihu/activities.ts | 2 ++
lib/routes/zhihu/xhu/activities.ts | 14 ++++++++------
lib/routes/zhihu/xhu/answers.ts | 2 +-
lib/routes/zhihu/xhu/collection.ts | 2 +-
lib/routes/zhihu/xhu/posts.ts | 2 +-
lib/routes/zhihu/xhu/question.ts | 6 +++---
lib/routes/zhihu/xhu/topic.ts | 8 ++++----
7 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/lib/routes/zhihu/activities.ts b/lib/routes/zhihu/activities.ts
index 73823c6d7..9ab887444 100644
--- a/lib/routes/zhihu/activities.ts
+++ b/lib/routes/zhihu/activities.ts
@@ -139,6 +139,8 @@ async function handler(ctx) {
description = detail.description;
url = `https://www.zhihu.com/roundtable/${detail.id}`;
break;
+ default:
+ description = `未知类型 ${item.target.type},请点击链接提交issue`;
}
return {
diff --git a/lib/routes/zhihu/xhu/activities.ts b/lib/routes/zhihu/xhu/activities.ts
index 2f48794f4..f51cc82eb 100644
--- a/lib/routes/zhihu/xhu/activities.ts
+++ b/lib/routes/zhihu/xhu/activities.ts
@@ -1,7 +1,7 @@
import { Route } from '@/types';
import got from '@/utils/got';
import auth from './auth';
-import utils from '../utils';
+import { processImage } from '../utils';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
@@ -37,7 +37,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const hexId = ctx.req.param('hexId');
const link = `https://www.zhihu.com/people/${hexId}`;
const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/activities?before_id=0&limit=20`;
@@ -62,7 +62,7 @@ async function handler(ctx) {
let title;
let description;
let url;
- const images = [];
+ const images: string[] = [];
let text = '';
let link = '';
let author = '';
@@ -71,13 +71,13 @@ async function handler(ctx) {
case 'answer':
title = detail.question.title;
author = detail.author.name;
- description = utils.ProcessImage(detail.content);
+ description = processImage(detail.content);
url = `https://www.zhihu.com/question/${detail.question.id}/answer/${detail.id}`;
break;
case 'article':
title = detail.title;
author = detail.author.name;
- description = utils.ProcessImage(detail.content);
+ description = processImage(detail.content);
url = `https://zhuanlan.zhihu.com/p/${detail.id}`;
break;
case 'pin':
@@ -119,7 +119,7 @@ async function handler(ctx) {
case 'question':
title = detail.title;
author = detail.author.name;
- description = utils.ProcessImage(detail.detail);
+ description = processImage(detail.detail);
url = `https://www.zhihu.com/question/${detail.id}`;
break;
case 'collection':
@@ -146,6 +146,8 @@ async function handler(ctx) {
description = detail.description;
url = `https://www.zhihu.com/roundtable/${detail.id}`;
break;
+ default:
+ description = `未知类型 ${item.target.type},请点击链接提交issue`;
}
return {
diff --git a/lib/routes/zhihu/xhu/answers.ts b/lib/routes/zhihu/xhu/answers.ts
index 31b894dc9..39dc67f99 100644
--- a/lib/routes/zhihu/xhu/answers.ts
+++ b/lib/routes/zhihu/xhu/answers.ts
@@ -28,7 +28,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const hexId = ctx.req.param('hexId');
const link = `https://www.zhihu.com/people/${hexId}/answers`;
const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/answers?limit=20&offset=0`;
diff --git a/lib/routes/zhihu/xhu/collection.ts b/lib/routes/zhihu/xhu/collection.ts
index ff978af28..b0ac9a705 100644
--- a/lib/routes/zhihu/xhu/collection.ts
+++ b/lib/routes/zhihu/xhu/collection.ts
@@ -28,7 +28,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const id = ctx.req.param('id');
const link = `https://www.zhihu.com/collection/${id}`;
diff --git a/lib/routes/zhihu/xhu/posts.ts b/lib/routes/zhihu/xhu/posts.ts
index b36cc767c..c71ea46de 100644
--- a/lib/routes/zhihu/xhu/posts.ts
+++ b/lib/routes/zhihu/xhu/posts.ts
@@ -22,7 +22,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const hexId = ctx.req.param('hexId');
const link = `https://www.zhihu.com/people/${hexId}/posts`;
const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/articles?limit=20&offset=0`;
diff --git a/lib/routes/zhihu/xhu/question.ts b/lib/routes/zhihu/xhu/question.ts
index 3bb007484..7eeaee78e 100644
--- a/lib/routes/zhihu/xhu/question.ts
+++ b/lib/routes/zhihu/xhu/question.ts
@@ -1,7 +1,7 @@
import { Route } from '@/types';
import got from '@/utils/got';
import auth from './auth';
-import utils from '../utils';
+import { processImage } from '../utils';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
@@ -29,7 +29,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const {
questionId,
sortBy = 'default', // default,created,updated
@@ -54,7 +54,7 @@ async function handler(ctx) {
const link = `https://www.zhihu.com/question/${questionId}/answer/${item.id}`;
const author = item.author.name;
const title = `${author}的回答:${item.excerpt}`;
- const description = `${author}的回答
${utils.ProcessImage(item.excerpt)}`;
+ const description = `${author}的回答
${processImage(item.excerpt)}`;
return {
title,
diff --git a/lib/routes/zhihu/xhu/topic.ts b/lib/routes/zhihu/xhu/topic.ts
index e98c7a145..da6556f14 100644
--- a/lib/routes/zhihu/xhu/topic.ts
+++ b/lib/routes/zhihu/xhu/topic.ts
@@ -1,7 +1,7 @@
import { Route } from '@/types';
import got from '@/utils/got';
import auth from './auth';
-import utils from '../utils';
+import { processImage } from '../utils';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
@@ -28,7 +28,7 @@ export const route: Route = {
};
async function handler(ctx) {
- const xhuCookie = await auth.getCookie(ctx);
+ const xhuCookie = await auth.getCookie();
const topicId = ctx.req.param('topicId');
const link = `https://www.zhihu.com/topic/${topicId}/newest`;
const url = `https://api.zhihuvvv.workers.dev/topics/${topicId}/feeds/timeline_activity?before_id=0&limit=20`;
@@ -51,13 +51,13 @@ async function handler(ctx) {
let title = '';
let description = '';
let link = '';
- let pubDate = '';
+ let pubDate = new Date();
let author = '';
switch (type) {
case 'answer':
title = `${item.question.title}-${item.author.name}的回答:${item.excerpt}`;
- description = `${item.question.title}
${item.author.name}的回答
${utils.ProcessImage(item.content)}`;
+ description = `${item.question.title}
${item.author.name}的回答
${processImage(item.content)}`;
link = `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`;
pubDate = parseDate(item.updated_time * 1000);
author = item.author.name;