Files
RSSHub/lib/v2/apple/apps.js
T
Ethan Shen fb40ef2e8a fix(route): Apple App Store platform (#13420)
* fix(route): Apple App Store platform

* Update website/docs/routes/program-update.md

---------
2023-09-27 21:53:36 +08:00

52 lines
1.8 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { id, country } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 100;
const rootUrl = 'https://apps.apple.com';
const currentUrl = new URL(`${country}/app/${id}`, rootUrl).href;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
const webPlatform = $('meta[property="og:site_name"]').prop('content');
const subtitle = $('h2.whats-new__headline').text() || "What's New";
const appData = JSON.parse(Object.values(JSON.parse($('script#shoebox-media-api-cache-apps').text()))[0]);
const attributes = appData.d[0].attributes;
const appName = attributes.name;
const artistName = attributes.artistName;
const platform = Object.values(attributes.platformAttributes)[0]; // may incldes osx appletvos, ios, etc.
const items = platform.versionHistory.slice(0, limit).map((item) => ({
title: `${appName} ${item.versionDisplay}`,
link: currentUrl,
description: item.releaseNotes?.replace(/\n/g, '<br>'),
guid: `apple:apps:update:${country}:${id}:${item.versionDisplay}`,
pubDate: parseDate(item.releaseTimestamp),
}));
const icon = new URL('favicon.ico', rootUrl).href;
ctx.state.data = {
item: items,
title: `${appName} for ${/^App/.test(webPlatform) ? 'iOS' : 'macOS'} ${subtitle}`,
link: currentUrl,
description: platform.description.standard?.replace(/\n/g, ' '),
language: $('html').prop('lang'),
image: $('meta[property="og:image"]').prop('content'),
icon,
logo: icon,
subtitle: appName,
author: artistName,
};
ctx.state.json = {
appData,
};
};