feat: add chocolatey (#3472)

This commit is contained in:
wucong
2019-11-25 11:42:42 +08:00
committed by DIYgod
parent 65fe6e0316
commit cf5d8805f7
3 changed files with 66 additions and 0 deletions

View File

@@ -44,6 +44,12 @@ pageClass: routes
<Route author="cielpy" example="/bugly/changelog/1" path="/bugly/changelog/:platform" :paramsDesc="['平台类型, 必选, 1 为 Android, 2 为 iOS']"/>
## Chocolatey
### 软件更新
<Route author="woodgear" example="/chocolatey/software/GoogleChrome" path="/chocolatey/software"/>
## CurseForge
### 文件更新

View File

@@ -1992,4 +1992,7 @@ router.get('/fanfou/public_timeline/:keyword', require('./routes/fanfou/public_t
// Remote Work
router.get('/remote-work/:caty?', require('./routes/remote-work/index'));
// chocolatey
router.get('/chocolatey/software/:name?', require('./routes/chocolatey/software'));
module.exports = router;

View File

@@ -0,0 +1,57 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
async function get_software_raw_html(link) {
const response = await got({
method: 'get',
url: link,
});
return response.body;
}
function pick_versions(raw_html) {
const $ = cheerio.load(raw_html);
const items = [];
$('#versionhistory table tbody tr').each((_row_index, row) => {
const software = {};
$('td', row).each((col_index, col) => {
if ($(col).hasClass('version')) {
const href = $('a', col).attr('href');
let version = '';
if (href) {
version = href.split('/').slice(-1)[0];
}
software.version = version;
}
if (col_index === 0) {
software.software = $(col)
.text()
.trim();
}
if (col_index === 2) {
software.time = $(col).text();
}
});
items.push(software);
});
return items;
}
module.exports = async (ctx) => {
const software_name = ctx.params.name;
const software_link = `https://chocolatey.org/packages/${software_name}`;
const raw = await get_software_raw_html(software_link);
const items = pick_versions(raw);
const rsshub_object = {
name: software_name,
link: software_link,
item: items.map((i) => {
const link = `https://chocolatey.org/packages/${software_name}/${i.version}`;
const ret = { title: i.software, link, description: `update_time: ${i.time}` };
return ret;
}),
};
ctx.state.data = rsshub_object;
};