RSSHub/lib/routes/appstore/update.js

39 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const country = ctx.params.country;
const url = `https://itunes.apple.com/${country}/app/${id}`;
const res = await axios({
method: 'get',
url,
});
const data = res.data;
const $ = cheerio.load(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 item = {};
$('.whats-new').each(function() {
const version = $('.whats-new__latest__version')
.text()
.split(' ')[1];
item.title = `${titleTags.text().trim()} ${version}`;
item.description = $('.whats-new__content .we-truncate').html();
item.link = url;
item.guid = id + version;
});
ctx.state.data = {
title,
link: url,
item: [item],
};
};