mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
feat: 增加Discuz通用路由 (#3721)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const iconv = require('iconv-lite');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const date = require('@/utils/date');
|
||||
|
||||
@@ -38,8 +39,17 @@ function getProp(data, prop, $) {
|
||||
}
|
||||
|
||||
async function buildData(data) {
|
||||
const response = (await got.get(data.url)).data;
|
||||
const $ = cheerio.load(response);
|
||||
const response = await got.get(data.url);
|
||||
const contentType = response.headers['content-type'] || '';
|
||||
// 若没有指定编码,则默认utf-8
|
||||
let charset = 'utf-8';
|
||||
for (const attr of contentType.split(';')) {
|
||||
if (attr.indexOf('charset=') >= 0) {
|
||||
charset = attr.split('=').pop();
|
||||
}
|
||||
}
|
||||
const responseData = charset === 'utf-8' ? response.data : iconv.decode((await got.get({ url: data.url, responseType: 'buffer' })).data, charset);
|
||||
const $ = cheerio.load(responseData);
|
||||
const $item = $(data.item.item);
|
||||
// 这里应该是可以通过参数注入一些代码的,不过应该无伤大雅
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user