Files
RSSHub/lib/v2/mihoyo/bbs.js
T
CaoMeiYouRen b70e690a5c feat(route): 新增 米游社 路由 (#9404)
* feat: 优化B站动态转发内容中的图片和视频

* style: 修复格式错误

* fix: 修复 B站动态转发多图的图片缺失

* style: 整理代码格式

* style: 整理代码格式

* fix: 修复B站动态转发视频缺失标题

* fix: 移除了部分不必要的代码

* fix: 修复b站动态中转发直播间动态出现undefined;整理部分代码

* style: 整理代码格式

* fix: 补充b站动态中转发活动的信息

* fix: 修正代码格式

* fix: b站动态转发专题页缺少标题;整理部分代码

* fix: 修复图片错误

* fix: 修复专栏封面缺失的bug;增加B站动态格式总结

* style:修复格式问题

* fix: 修复/robots.txt路由

* fix

* chore: 合并冲突

* fix

* fix

* feat: 优化B站动态url

* fix: 改 \n 为<br>

* chore: 更新 npm registry

* feat: 完成 米游社路由和文档的编写

* fix: 修复 @vuepress/shared-utils 在 yarn.lock 的缺失

* chore: exact match

* fix: parseDate
2022-03-29 20:21:21 +08:00

63 lines
1.7 KiB
JavaScript

const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
// 游戏id
const GITS_MAP = {
1: '崩坏三',
2: '原神',
3: '崩坏二',
4: '未定事件簿',
6: '崩坏:星穹铁道',
};
// 公告类型
const TYPE_MAP = {
1: '公告',
2: '活动',
3: '资讯',
};
const renderDescription = (description, images) => art(path.join(__dirname, 'templates/description.art'), { description, images });
module.exports = async (ctx) => {
const { gids, type = '2', page_size = '20', last_id = '' } = ctx.params;
const query = new URLSearchParams({
gids,
type,
page_size,
last_id,
}).toString();
const url = `https://bbs-api.mihoyo.com/post/wapi/getNewsList?${query}`;
const response = await got({
method: 'get',
url,
});
const list = response?.data?.data?.list;
if (!list) {
throw new Error('未获取到数据!');
}
const title = `米游社 - ${GITS_MAP[gids] || ''} - ${TYPE_MAP[type] || ''}`;
const items = list.map((e) => {
const author = e.user.nickname;
const title = e.post.subject;
const link = `https://bbs.mihoyo.com/ys/article/${e.post.post_id}`;
const description = renderDescription(e.post.content, e.post.images);
const pubDate = parseDate(e.post.created_at * 1000);
return {
author,
title,
link,
description,
pubDate,
};
});
const data = {
title,
link: url,
item: items,
};
ctx.state.data = data;
};