mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-28 03:28:35 +08:00
fix(route): /163/dy2/:id, 网易号 (#15081)
* fix(route): /163/dy2/:id, remove iconv module, use data from got directly instead of decoding data with content-type * update /163/dy.ts --------- Co-authored-by: luis <sherlock563768884@qq.com>
This commit is contained in:
@@ -30,7 +30,6 @@ async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
|
||||
const response = await got(`https://dy.163.com/v2/article/list.do?pageNo=1&wemediaId=${id}&size=10`);
|
||||
const charset = response.headers['content-type'].split('=')[1];
|
||||
|
||||
const list = response.data.data.list.map((e) => ({
|
||||
title: e.title,
|
||||
@@ -40,7 +39,7 @@ async function handler(ctx) {
|
||||
imgsrc: e.imgsrc,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((e) => parseDyArticle(charset, e, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((e) => parseDyArticle(e, cache.tryGet)));
|
||||
|
||||
return {
|
||||
title: `网易号 - ${list[0].author}`,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import iconv from 'iconv-lite';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { parseDyArticle } from './utils';
|
||||
@@ -31,12 +30,8 @@ async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
const limit = ctx.req.query('limit') ?? 30;
|
||||
const url = `https://www.163.com/dy/media/${id}.html`;
|
||||
|
||||
const response = await got(url, { responseType: 'buffer' });
|
||||
|
||||
const charset = response.headers['content-type'].split('=')[1];
|
||||
const data = iconv.decode(response.data, charset);
|
||||
const $ = load(data);
|
||||
const res = await got(url);
|
||||
const $ = load(res.data);
|
||||
|
||||
const list = $('.tab_content ul li')
|
||||
.slice(0, limit)
|
||||
@@ -52,7 +47,7 @@ async function handler(ctx) {
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseDyArticle(charset, item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseDyArticle(item, cache.tryGet)));
|
||||
|
||||
return {
|
||||
title: `${$('head title').text()} - 网易号`,
|
||||
|
||||
@@ -3,18 +3,16 @@ const __dirname = getCurrentPath(import.meta.url);
|
||||
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import iconv from 'iconv-lite';
|
||||
import { art } from '@/utils/render';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const parseDyArticle = (charset, item, tryGet) =>
|
||||
const parseDyArticle = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const response = await got(item.link, {
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
||||
const html = iconv.decode(response.data, charset);
|
||||
const $ = load(html);
|
||||
const $ = load(response.data);
|
||||
|
||||
$('.post_main img').each((_, i) => {
|
||||
if (!i.attribs.src) {
|
||||
|
||||
Reference in New Issue
Block a user