mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 11:07:54 +08:00
Motivation: There are multiple routes that need to fetch articles from WeChat MP. However, letting them fetch articles by themselves could potentially lead to cache key collisions. Even if cache key collisions do not occur, un-normalized URL could potentially lead to duplicated requests. What's more, articles from WeChat MP have weird formats and need to be fixed. Creating a universal function to do this work can create some ease for new route contributors. Note: In order to make this PR atomic as much as possible, I did not touch those broken routes. Once this PR is merged, I will try to fix them. Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const dayjs = require('dayjs');
|
|
const { finishArticleItem } = require('@/utils/wechat-mp');
|
|
|
|
module.exports = async (ctx) => {
|
|
const { biz, aid } = ctx.params;
|
|
const aidurl = `&album_id=${aid}`;
|
|
|
|
const HTMLresponse = await got({
|
|
method: 'get',
|
|
url: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`,
|
|
});
|
|
const $ = cheerio.load(HTMLresponse.data);
|
|
const list = $('li').get();
|
|
const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text();
|
|
const articledata = await Promise.all(
|
|
list.map(async (item) => {
|
|
const link = $(item).attr('data-link').replace('http://', 'https://');
|
|
const title = $(item).attr('data-title');
|
|
const single = {
|
|
title,
|
|
link,
|
|
guid: link,
|
|
};
|
|
return await finishArticleItem(ctx, single);
|
|
})
|
|
);
|
|
ctx.state.data = {
|
|
title: mptitle,
|
|
link: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`,
|
|
item: list.map((item, index) => ({
|
|
title: articledata[index].title,
|
|
description: $(item).find('.album__item-img').html() + `<br><br>${articledata[index].description}`,
|
|
link: articledata[index].link,
|
|
guid: articledata[index].guid,
|
|
author: articledata[index].author,
|
|
pubDate: dayjs.unix($(item).find('.js_article_create_time').text()).format(),
|
|
})),
|
|
};
|
|
};
|