Files
RSSHub/lib/routes/mihoyo/bh2.js
T
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

44 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = 'https://www.mihoyo.com/news/getNotice';
let type = ctx.params.type;
const typeArr = ['new', 'version', 'gach', 'event'];
if (typeArr.indexOf(type) === -1) {
type = typeArr[0];
}
const index = typeArr.indexOf(type) + 1 || 1;
const response = await got({
method: 'post',
url,
headers: {
Referer: url,
'x-requested-with': 'XMLHttpRequest',
},
});
const data = response.data.data[type] || [];
const title = `崩坏2-${type}`;
ctx.state.data = {
title,
link: 'http://www.mihoyo.com/news',
description: title,
item: data.map((item) => {
const pubDate = new Date(item.time);
pubDate.setTime(pubDate.getTime() + 8 * 60 * 60 * 1000);
return {
title: item.title,
description: item.title,
pubDate: pubDate.toUTCString(),
link: `http://www.mihoyo.com/news?para=${index}_${item.id}`,
};
}),
};
};