mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-19 09:52:21 +08:00
fix(route): Apple App Store Update with platform (#13466)
This commit is contained in:
+68
-12
@@ -2,8 +2,30 @@ const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const platformIds = {
|
||||
osx: 'macOS',
|
||||
ios: 'iOS',
|
||||
appletvos: 'tvOS',
|
||||
};
|
||||
|
||||
const platforms = {
|
||||
macos: 'osx',
|
||||
ios: 'ios',
|
||||
tvos: 'appletvos',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id, country } = ctx.params;
|
||||
const { country, id } = ctx.params;
|
||||
let { platform } = ctx.params;
|
||||
|
||||
let platformId;
|
||||
|
||||
if (platform) {
|
||||
platform = platform.toLowerCase();
|
||||
platformId = platforms.hasOwnProperty(platform) ? platforms[platform] : platform;
|
||||
}
|
||||
platform = undefined;
|
||||
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 100;
|
||||
|
||||
const rootUrl = 'https://apps.apple.com';
|
||||
@@ -13,36 +35,70 @@ module.exports = async (ctx) => {
|
||||
|
||||
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 platformAttributes = attributes.platformAttributes;
|
||||
|
||||
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),
|
||||
}));
|
||||
let items = [];
|
||||
let title = '';
|
||||
let description = '';
|
||||
|
||||
if (platformId && platformAttributes.hasOwnProperty(platformId)) {
|
||||
platform = platformIds.hasOwnProperty(platformId) ? platformIds[platformId] : platformId;
|
||||
|
||||
const platformAttribute = platformAttributes[platformId];
|
||||
|
||||
items = platformAttribute.versionHistory;
|
||||
title = `${appName}${platform ? ` for ${platform} ` : ' '}${subtitle}`;
|
||||
description = platformAttribute.description.standard;
|
||||
} else {
|
||||
title = `${appName} ${subtitle}`;
|
||||
for (const pid of Object.keys(platformAttributes)) {
|
||||
const platformAttribute = platformAttributes[pid];
|
||||
items = [
|
||||
...items,
|
||||
...platformAttribute.versionHistory.map((v) => ({
|
||||
...v,
|
||||
platformId: pid,
|
||||
})),
|
||||
];
|
||||
description += platformAttribute.description.standard;
|
||||
}
|
||||
}
|
||||
|
||||
items = items.slice(0, limit).map((item) => {
|
||||
const pid = item.platformId ?? platformId;
|
||||
const p = platform ? platform : platformIds.hasOwnProperty(pid) ? platformIds[pid] : pid;
|
||||
|
||||
return {
|
||||
title: `${appName} ${item.versionDisplay} for ${p}`,
|
||||
link: currentUrl,
|
||||
description: item.releaseNotes?.replace(/\n/g, '<br>'),
|
||||
category: [p],
|
||||
guid: `apple/apps/${country}/${id}/${pid}#${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}`,
|
||||
title,
|
||||
link: currentUrl,
|
||||
description: platform.description.standard?.replace(/\n/g, ' '),
|
||||
description: description?.replace(/\n/g, ' '),
|
||||
language: $('html').prop('lang'),
|
||||
image: $('meta[property="og:image"]').prop('content'),
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: appName,
|
||||
author: artistName,
|
||||
allowEmpty: true,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
'/apps/update/:country/:id': ['EkkoG', 'nczitzk'],
|
||||
'/apps/update/:country/:id/:platform?': ['EkkoG', 'nczitzk'],
|
||||
'/exchange_repair/:country?': ['metowolf', 'HenryQW', 'kt286'],
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/apps/update/:country/:id', require('./apps'));
|
||||
router.get('/apps/update/:country/:id/:platform?', require('./apps'));
|
||||
router.get('/exchange_repair/:country?', require('./exchange_repair'));
|
||||
};
|
||||
|
||||
@@ -59,7 +59,11 @@ The parameters can be extracted from the Release page URL: `https://install.appc
|
||||
|
||||
### App Update {#app-store-mac-app-store-app-update}
|
||||
|
||||
<Route author="EkkoG nczitzk" example="/apple/apps/update/us/id408709785" path="/apple/apps/update/:country/:id" paramsDesc={['App Store Country, obtain from the app URL, see below', 'App id, obtain from the app URL']} radar="1" rssbud="1">
|
||||
<Route author="EkkoG nczitzk" example="/apple/apps/update/us/id408709785" path="/apple/apps/update/:country/:id/:platform?" paramsDesc={['App Store Country, obtain from the app URL, see below', 'App id, obtain from the app URL', 'App Platform, see below, all by default']} radar="1" rssbud="1">
|
||||
|
||||
| All | iOS | macOS | tvOS |
|
||||
| --- | --- | ----- | ---- |
|
||||
| | iOS | macOS | tvOS |
|
||||
|
||||
:::tip
|
||||
|
||||
|
||||
Reference in New Issue
Block a user