diff --git a/lib/routes/furaffinity/search.js b/lib/routes/furaffinity/search.js index 3c0d7a3bcb..39e362cc16 100644 --- a/lib/routes/furaffinity/search.js +++ b/lib/routes/furaffinity/search.js @@ -1,15 +1,16 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); // 发起 HTTP GET 请求 module.exports = async (ctx) => { - // 传入参数 + //传入参数 const nsfw = String(ctx.params.nsfw); const keyword = String(ctx.params.keyword); - // 添加参数keyword以及判断传入的参数nsfw - let url = `https://faexport.spangle.org.uk/search.json?q=${keyword}?sfw=1`; - if (nsfw === '1' || keyword === '1') { - url = `https://faexport.spangle.org.uk/search.json?q=${keyword}`; + //添加参数keyword以及判断传入的参数nsfw + let url = `https://faexport.spangle.org.uk/search.rss?q=${keyword}?sfw=1`; + if (nsfw === '1' || keyword === '1' ) { + url = `https://faexport.spangle.org.uk/search.rss?q=${keyword}`; } const response = await got({ @@ -20,7 +21,13 @@ module.exports = async (ctx) => { }, }); + // 使用 cheerio 加载返回的 HTML const data = response.data; + const $ = cheerio.load(data, { + xmlMode: true + }); + + const list = $('item'); ctx.state.data = { // 源标题 @@ -30,17 +37,19 @@ module.exports = async (ctx) => { // 源说明 description: `Fur Affinity ${keyword}'s Search List`, - // 遍历此前获取的数据 - item: data.map((item) => ({ - // 标题 - title: item.title, - // 正文 - description: ``, - // 链接 - link: item.link, - // 作者 - author: item.name, - // 由于源API未提供日期,故无pubDate - })), - }; + //遍历此前获取的数据 + item: + list && + list.map((index, item) => { + item = $(item); + return { + title: item.find("title").text(), + description: item.find("description").text(), + link: item.find("link").text(), + pubDate: new Date(item.find("pubDate").text()).toUTCString(), + //由于源API未提供作者信息,故无author + }; + }) + .get(), + } };