feat(route): qbittorrent news (#9524)

This commit is contained in:
Tony 2022-04-11 11:17:09 -11:00 committed by GitHub
parent 84f282b2fe
commit fb2a407b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 84 additions and 0 deletions

View File

@ -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

View File

@ -360,6 +360,12 @@ pageClass: routes
</Route>
## qBittorrent
### 消息
<Route author="TonyRL" example="/qbittorrent/news" path="/qbittorrent/news" radar="1" rssbud="1"/>
## QNAP
### Release Notes

View File

@ -0,0 +1,3 @@
module.exports = {
'/news': ['TonyRL'],
};

View File

@ -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,
};
};

View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/news', require('./news'));
};