feat(route): qbittorrent news (#9524)
This commit is contained in:
parent
84f282b2fe
commit
fb2a407b02
|
|
@ -305,6 +305,12 @@ Refer to [#minecraft](/en/game.html#minecraft)
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## qBittorrent
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="TonyRL" example="/qbittorrent/news" path="/qbittorrent/news" radar="1" rssbud="1"/>
|
||||
|
||||
## QNAP
|
||||
|
||||
### Release Notes
|
||||
|
|
|
|||
|
|
@ -360,6 +360,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## qBittorrent
|
||||
|
||||
### 消息
|
||||
|
||||
<Route author="TonyRL" example="/qbittorrent/news" path="/qbittorrent/news" radar="1" rssbud="1"/>
|
||||
|
||||
## QNAP
|
||||
|
||||
### Release Notes
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const config = require('@/config').value;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.qbittorrent.org';
|
||||
|
||||
const response = await ctx.cache.tryGet(
|
||||
`${baseUrl}/news.php`,
|
||||
async () =>
|
||||
(
|
||||
await got(`${baseUrl}/news.php`, {
|
||||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
})
|
||||
).data,
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const item = $('.stretcher')
|
||||
.find('h3')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const pubDate = item
|
||||
.text()
|
||||
.split(' - ')[0]
|
||||
.replace(/\w{3,6}day/, '');
|
||||
const title = item.text().split(' - ')[1];
|
||||
let description = '';
|
||||
// nextUntil() does not work here
|
||||
while (item.next().length && item.next().get(0).tagName !== 'h3') {
|
||||
item = item.next();
|
||||
description += item.html();
|
||||
}
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
pubDate: parseDate(pubDate, 'MMMM D YYYY'),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'qBittorrent News',
|
||||
link: `${baseUrl}/news.php`,
|
||||
item,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'qbittorrent.org': {
|
||||
_name: 'qBittorrent',
|
||||
'.': [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/program-update.html#qbittorrent',
|
||||
source: ['/news.php', '/'],
|
||||
target: '/qbittorrent/news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/news', require('./news'));
|
||||
};
|
||||
Loading…
Reference in New Issue