Skip to content

Commit

Permalink
fix(route/sohu): add image URL decryption for fetched articles (DIYgo…
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Dec 9, 2024
1 parent 74f50c3 commit 8434009
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/routes/sohu/mp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as cheerio from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import path from 'node:path';
import { art } from '@/utils/render';
import CryptoJS from 'crypto-js';

export const route: Route = {
path: '/mp/:xpt',
Expand Down Expand Up @@ -39,6 +40,15 @@ function randomString(length = 32) {
}
const defaultSUV = '1612268936507kas0gk';

function decryptImageUrl(cipherText) {
const key = CryptoJS.enc.Utf8.parse('www.sohu.com6666');
const cipher = CryptoJS.AES.decrypt(cipherText, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
});
return cipher.toString(CryptoJS.enc.Utf8);
}

function fetchArticle(item) {
return cache.tryGet(item.link, async () => {
const response = await ofetch(item.link);
Expand All @@ -64,6 +74,13 @@ function fetchArticle(item) {
article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => {
$(e).remove();
});
article.find('img').each((_, e) => {
const $e = $(e);
if ($e.attr('data-src') && !$e.attr('src')) {
$e.attr('src', decryptImageUrl($e.attr('data-src')));
$e.removeAttr('data-src');
}
});

item.description = article.html();
}
Expand Down

0 comments on commit 8434009

Please sign in to comment.