mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): discuz use ofetch (#18543)
* fix(route): discuz use ofetch * fix(route): discuz use ofetch with charset handling
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import iconv from 'iconv-lite';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -22,14 +22,13 @@ function fixUrl(itemLink, baseUrl) {
|
||||
// discuz 7.x 与 discuz x系列 通用文章内容抓取
|
||||
async function loadContent(itemLink, charset, header) {
|
||||
// 处理编码问题
|
||||
const response = await got({
|
||||
const response = await ofetch.raw(itemLink, {
|
||||
method: 'get',
|
||||
url: itemLink,
|
||||
responseType: 'buffer',
|
||||
responseType: 'arrayBuffer',
|
||||
headers: header,
|
||||
});
|
||||
|
||||
const responseData = iconv.decode(response.data, charset ?? 'utf-8');
|
||||
const responseData = iconv.decode(Buffer.from(response._data), charset ?? 'utf-8');
|
||||
if (!responseData) {
|
||||
const description = '获取详细内容失败';
|
||||
return { description };
|
||||
@@ -77,14 +76,13 @@ async function handler(ctx) {
|
||||
Cookie: cookie,
|
||||
};
|
||||
|
||||
const response = await got({
|
||||
const response = await ofetch.raw(link, {
|
||||
method: 'get',
|
||||
url: link,
|
||||
responseType: 'buffer',
|
||||
responseType: 'arrayBuffer',
|
||||
headers: header,
|
||||
});
|
||||
|
||||
const responseData = response.data;
|
||||
const responseData = Buffer.from(response._data);
|
||||
// 若没有指定编码,则默认utf-8
|
||||
const contentType = response.headers['content-type'] || '';
|
||||
let $ = load(iconv.decode(responseData, 'utf-8'));
|
||||
|
||||
Reference in New Issue
Block a user