Files
RSSHub/lib/routes/wechat/msgalbum.ts
T
Tony a5e2e295dc refactor: fix all get to toArray (#19000)
* refactor: fix all get

* fix(utils/common-config): charset case compare

* Revert "fix(utils/common-config): charset case compare"

This reverts commit 3c1880f2fad53ad2cafddcee7741390fd46fa3d2.

* fix: nga

* fix: notateslaapp

* fix: ps

* fix: xjtu

* fix: enforce error on restricted syntax for get calls

* fix: eslint

* fix: more eslint
2025-05-04 05:24:53 +08:00

62 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import dayjs from 'dayjs';
import { finishArticleItem } from '@/utils/wechat-mp';
export const route: Route = {
path: '/mp/msgalbum/:biz/:aid',
categories: ['new-media'],
example: '/wechat/mp/msgalbum/MzA3MDM3NjE5NQ==/1375870284640911361',
parameters: { biz: '公众号id', aid: 'Tag id' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '公众号文章话题 Tag',
maintainers: ['MisteryMonster'],
handler,
description: `一些公众号(如看理想)会在微信文章里添加 Tag ,点入 Tag 的链接如 \`https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzA3MDM3NjE5NQ==&action=getalbum&album_id=1375870284640911361\`,其中\`biz\` 为 \`MzA3MDM3NjE5NQ==\`,\`aid\` 为 \`1375870284640911361\`。`,
};
async function handler(ctx) {
const { biz, aid } = ctx.req.param();
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 $ = load(HTMLresponse.data);
const list = $('li').toArray();
const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text();
const articledata = await Promise.all(
list.map((item) => {
const link = $(item).attr('data-link').replace('http://', 'https://');
const title = $(item).attr('data-title');
const single = {
title,
link,
guid: link,
};
return finishArticleItem(single);
})
);
return {
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(),
})),
};
}