diff --git a/lib/v2/apple/apps.js b/lib/v2/apple/apps.js index 9aee97bfa..3d12ba5ea 100644 --- a/lib/v2/apple/apps.js +++ b/lib/v2/apple/apps.js @@ -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, '
'), - 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, '
'), + 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 = { diff --git a/lib/v2/apple/maintainer.js b/lib/v2/apple/maintainer.js index 1589124a1..afc37f48e 100644 --- a/lib/v2/apple/maintainer.js +++ b/lib/v2/apple/maintainer.js @@ -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'], }; diff --git a/lib/v2/apple/router.js b/lib/v2/apple/router.js index c9a52ef54..14bc66ed1 100644 --- a/lib/v2/apple/router.js +++ b/lib/v2/apple/router.js @@ -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')); }; diff --git a/website/docs/routes/program-update.md b/website/docs/routes/program-update.md index 286db8622..1798332d9 100644 --- a/website/docs/routes/program-update.md +++ b/website/docs/routes/program-update.md @@ -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} - + + +| All | iOS | macOS | tvOS | +| --- | --- | ----- | ---- | +| | iOS | macOS | tvOS | :::tip