Files
RSSHub/lib/v2/appstore/update.js
Fatpandac 77f3e710fa fix(route): appstore refactor to V2 (#9177)
* fix(route): appstore refactor to V2

* fix(route): add radar.js

* fix: remove legacy url.resolve
2022-02-25 00:14:13 +08:00

38 lines
1.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const country = ctx.params.country;
const url = `https://apps.apple.com/${country}/app/${id}`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const titleTags = $('h1').attr('class', 'product-header__title');
titleTags.find('span').remove();
const platform = $('.we-localnav__title__product').text();
const title = `${titleTags.text().trim()} for ${platform === 'App Store' ? 'iOS' : 'macOS'} ${country === 'cn' ? '更新' : 'Update'}`;
const items = [];
if ($('.whats-new').length > 0) {
$('.whats-new').each(() => {
const version = $('.whats-new__latest__version').text().split(' ')[1];
const date = $('.whats-new__content time').attr('aria-label');
const item = {};
item.title = `${titleTags.text().trim()} ${version}`;
item.description = $('.whats-new__content .we-truncate').html();
item.link = url;
item.guid = id + version;
item.pubDate = date;
items.push(item);
});
}
ctx.state.data = {
title,
link: url,
item: items,
};
};