Skip to content

Commit cca3733

Browse files
authored
fix(route/sohu): add auth token (#19774)
* fix(route/sohu): add auth token * fix(route/sohu): update selector for publication date
1 parent f455f54 commit cca3733

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/routes/sohu/mp.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cache from '@/utils/cache';
44
import ofetch from '@/utils/ofetch';
55
import * as cheerio from 'cheerio';
66
import { parseDate } from '@/utils/parse-date';
7+
import timezone from '@/utils/timezone';
78
import path from 'node:path';
89
import { art } from '@/utils/render';
910
import CryptoJS from 'crypto-js';
@@ -47,13 +48,20 @@ function decryptImageUrl(cipherText) {
4748
return cipher.toString(CryptoJS.enc.Utf8);
4849
}
4950

51+
function createAuthToken() {
52+
const t = Date.now();
53+
const e = 't' + t;
54+
return 'v1' + t + CryptoJS.HmacSHA1(e, '439642a904ef43d092d45509cdc4391c').toString();
55+
}
56+
5057
function fetchArticle(item) {
5158
return cache.tryGet(item.link, async () => {
5259
const response = await ofetch(item.link);
5360
const $ = cheerio.load(response);
5461

5562
$('.original-title, .lookall-box').remove();
5663
item.author = item.author || $('span[data-role="original-link"] a').text();
64+
item.pubDate = timezone(parseDate($('meta[itemprop="dateUpdate"]').attr('content')), 8);
5765

5866
if (/window\.sohu_mp\.article_video/.test($('script').text())) {
5967
const videoSrc = $('script')
@@ -128,6 +136,8 @@ async function handler(ctx) {
128136
.match(/({.*})/)?.[1]
129137
);
130138
const renderData = blockRenderData[Object.keys(blockRenderData).find((e) => e.startsWith('FeedSlideloadAuthor'))];
139+
const briefIntroductionCard = blockRenderData[Object.keys(blockRenderData).find((e) => e.startsWith('BriefIntroductionCard'))].param.data.list[0];
140+
131141
const globalConst = JSON.parse(
132142
$('script:contains("globalConst")')
133143
.text()
@@ -153,7 +163,7 @@ async function handler(ctx) {
153163
},
154164
body: {
155165
pvId: CBDRenderConst.COMMONCONFIG.pvId || `${Date.now()}_${randomString(7)}`,
156-
pageId: `${Date.now()}_${defaultSUV.slice(0, -5)}_${randomString(3)}`,
166+
pageId: `${Date.now()}_${defaultSUV?.slice(0, -5)}_${randomString(3)}`,
157167
mainContent: {
158168
productType: contentData.businessType || '13',
159169
productId: contentData.id || '324',
@@ -174,34 +184,35 @@ async function handler(ctx) {
174184
size: 20,
175185
pro: renderData.param.pro || '0,1,3,4,5',
176186
feedType: renderData.param.feedType || 'XTOPIC_SYNTHETICAL',
177-
view: '',
187+
view: 'operateFeedMode',
178188
innerTag: renderData.param.data2.reqParam.content.innerTag || 'work',
179189
spm: renderData.param.data2.reqParam.content.spm || 'smpc.channel_248.block3_308_hHsK47_2_fd',
180190
page: 1,
181-
requestId: `${Date.now()}_${randomString(13)}_${contentData.id}`,
191+
requestId: `${Date.now()}${randomString(7)}_${contentData.id}`,
182192
},
183193
adInfo: {},
184194
context: {
185195
mkey: globalConst.mkeyConst_mkey, // legacy ID
186196
},
187197
},
188198
],
199+
asId: createAuthToken(),
189200
},
190201
});
191202

192203
const list = blockData.data[renderData.param.data2.reqParam.tplCompKey].list.map((item) => ({
193204
title: item.title,
194205
description: item.brief,
195-
link: `https://www.sohu.com/a/${item.id}_${item.authorId}`,
196-
author: item.authorName,
197-
pubDate: parseDate(item.postTime, 'x'),
206+
link: `https://www.sohu.com/a/${item.id}_${globalConst.mkeyConst_mkey}`,
198207
}));
199208

200209
const items = await Promise.all(list.map((e) => fetchArticle(e)));
201210

202211
return {
203212
title: `搜狐号 - ${globalConst.title}`,
213+
description: briefIntroductionCard.column_9_text,
204214
link: originalRequest.url,
215+
image: `https:${briefIntroductionCard.column_2_image}`,
205216
item: items,
206217
};
207218
}

0 commit comments

Comments
 (0)