mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +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>
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
const { finishArticleItem } = require('@/utils/wechat-mp');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id;
|
|
|
|
const baseUrl = 'https://api.feeddd.org';
|
|
const apiUrl = `${baseUrl}/feeds/${id}/json`;
|
|
|
|
const response = await got(apiUrl);
|
|
|
|
let items = response.data.items.map((item) => ({
|
|
title: item.title,
|
|
// the date is when the article was grabbed, not published, `finishArticleItem` will fix this
|
|
pubDate: parseDate(item.date_modified),
|
|
link: item.url,
|
|
guid: item.id,
|
|
}));
|
|
|
|
items = await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
|
|
|
ctx.state.data = {
|
|
title: response.data.title,
|
|
link: response.data.feed_url,
|
|
description: response.data.title,
|
|
item: items,
|
|
allowEmpty: true,
|
|
};
|
|
|
|
ctx.state.json = {
|
|
title: response.data.title,
|
|
link: response.data.feed_url,
|
|
description: response.data.title,
|
|
item: items,
|
|
};
|
|
};
|