From fb40ef2e8ab7e04c92d4edce1eee27f4967c0526 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 27 Sep 2023 21:53:36 +0800 Subject: [PATCH] fix(route): Apple App Store platform (#13420) * fix(route): Apple App Store platform * Update website/docs/routes/program-update.md --------- --- lib/v2/apple/apps.js | 39 ++++++++++++++++++--------- lib/v2/apple/maintainer.js | 2 +- lib/v2/apple/radar.js | 6 ++--- website/docs/routes/program-update.md | 10 ++++++- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lib/v2/apple/apps.js b/lib/v2/apple/apps.js index 35ce321e15..9aee97bfa2 100644 --- a/lib/v2/apple/apps.js +++ b/lib/v2/apple/apps.js @@ -4,30 +4,45 @@ const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const { id, country } = ctx.params; - const url = `https://apps.apple.com/${country}/app/${id}`; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 100; - const res = await got(url); - const $ = cheerio.load(res.data); + const rootUrl = 'https://apps.apple.com'; + const currentUrl = new URL(`${country}/app/${id}`, rootUrl).href; - const webPlatform = $('.we-localnav__title__product').text(); + 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 appName = appData.d[0].attributes.name; - const platform = Object.values(appData.d[0].attributes.platformAttributes)[0]; // may incldes osx appletvos, ios, etc. + 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.map((item) => ({ + const items = platform.versionHistory.slice(0, limit).map((item) => ({ title: `${appName} ${item.versionDisplay}`, + link: currentUrl, description: item.releaseNotes?.replace(/\n/g, '
'), - pubDate: parseDate(item.releaseTimestamp), guid: `apple:apps:update:${country}:${id}:${item.versionDisplay}`, - link: url, + pubDate: parseDate(item.releaseTimestamp), })); + const icon = new URL('favicon.ico', rootUrl).href; + ctx.state.data = { - title: `${appName} for ${webPlatform === 'App Store' ? 'iOS' : 'macOS'} ${country === 'cn' ? '更新' : 'Update'}`, - description: platform.description.standard?.replace(/\n/g, ' '), - link: url, 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 = { diff --git a/lib/v2/apple/maintainer.js b/lib/v2/apple/maintainer.js index 5c93b99474..1589124a18 100644 --- a/lib/v2/apple/maintainer.js +++ b/lib/v2/apple/maintainer.js @@ -1,4 +1,4 @@ module.exports = { - '/apps/update/:country/:id': ['EkkoG'], + '/apps/update/:country/:id': ['EkkoG', 'nczitzk'], '/exchange_repair/:country?': ['metowolf', 'HenryQW', 'kt286'], }; diff --git a/lib/v2/apple/radar.js b/lib/v2/apple/radar.js index 0627820d2b..7ef62135cd 100644 --- a/lib/v2/apple/radar.js +++ b/lib/v2/apple/radar.js @@ -4,9 +4,9 @@ module.exports = { apps: [ { title: 'App Update', - docs: 'https://docs.rsshub.app/routes/program-update#app-store-mac-app-store', - source: ['/:contry/app/:appSlug/:id', '/:contry/app/:id'], - target: '/appstore/apps/update/:country/:id', + docs: 'https://docs.rsshub.app/routes/program-update#app-store-mac-app-store-app-update', + source: ['/:country/app/:appSlug/:id', '/:country/app/:id'], + target: '/apple/apps/update/:country/:id', }, ], support: [ diff --git a/website/docs/routes/program-update.md b/website/docs/routes/program-update.md index 260e74a197..286db8622e 100644 --- a/website/docs/routes/program-update.md +++ b/website/docs/routes/program-update.md @@ -59,7 +59,15 @@ The parameters can be extracted from the Release page URL: `https://install.appc ### App Update {#app-store-mac-app-store-app-update} - + + +:::tip + +For example, the URL of [GarageBand](https://apps.apple.com/us/app/messages/id408709785) in the App Store is . In this case, the `App Store Country` parameter for the route is `us`, and the `App id` parameter is `id1146560473`. So the route should be [`/apple/apps/update/us/id408709785`](https://rsshub.app/apple/apps/update/us/id408709785). + +::: + + ### Price Drop {#app-store-mac-app-store-price-drop}