diff --git a/lib/router.js b/lib/router.js index 79fd6c258..d9e2c44f2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -871,9 +871,6 @@ router.get('/guokr/:channel', lazyloadRouteHandler('./routes/guokr/calendar')); // router.get('/zaobao/:type/:section', lazyloadRouteHandler('./routes/zaobao/index')); // router.get('/zaobao/interactive-graphics', lazyloadRouteHandler('./routes/zaobao/interactive')); -// Apple -router.get('/apple/exchange_repair/:country?', lazyloadRouteHandler('./routes/apple/exchange_repair')); - // IPSW.me router.get('/ipsw/index/:ptype/:pname', lazyloadRouteHandler('./routes/ipsw/index')); diff --git a/lib/routes/apple/exchange_repair.js b/lib/routes/apple/exchange_repair.js deleted file mode 100644 index 36bbea2dd..000000000 --- a/lib/routes/apple/exchange_repair.js +++ /dev/null @@ -1,47 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); - -const host = 'https://support.apple.com/'; - -module.exports = async (ctx) => { - const country = ctx.params.country || ''; - const link = url.resolve(host, `${country}/exchange_repair/`); - - const response = await got.get(link); - const $ = cheerio.load(response.data); - const list = $('section.as-columns').get().slice(0, 5); - - const out = await Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const $a = $('.icon-chevronright').parent(); - const itemUrl = url.resolve(host, $a.attr('href')); - - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const response = await got.get(itemUrl); - const $$ = cheerio.load(response.data); - const description = $$('.main').html(); - - const single = { - title: $a.text(), - link: itemUrl, - author: 'Apple Inc.', - description, - }; - - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - - ctx.state.data = { - title: `Apple - ${$('.main>.richText h1').text()}`, - link, - item: out, - }; -}; diff --git a/lib/v2/apple/exchange_repair.js b/lib/v2/apple/exchange_repair.js new file mode 100644 index 000000000..7ed1f4c79 --- /dev/null +++ b/lib/v2/apple/exchange_repair.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const host = 'https://support.apple.com/'; + +module.exports = async (ctx) => { + const country = ctx.params.country ?? ''; + const link = new URL(`${country}/exchange_repair/`, host); + + const response = await got.get(link); + const $ = cheerio.load(response.data); + const list = $('section.as-columns').get().slice(0, 5); + + const out = await Promise.all( + list.map((item) => { + const $ = cheerio.load(item); + const $a = $('.icon-chevronright').parent(); + const itemUrl = new URL($a.attr('href'), host); + + return ctx.cache.tryGet(itemUrl, async () => { + const response = await got.get(itemUrl); + const $$ = cheerio.load(response.data); + const description = $$('.main').html(); + + return { + title: $a.text(), + link: itemUrl, + author: 'Apple Inc.', + description, + }; + }); + }) + ); + + ctx.state.data = { + title: `Apple - ${$('.main>.richText h1').text()}`, + link, + item: out, + }; +}; diff --git a/lib/v2/apple/maintainer.js b/lib/v2/apple/maintainer.js new file mode 100644 index 000000000..f20b561dc --- /dev/null +++ b/lib/v2/apple/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/exchange_repair/:country?': ['metowolf', 'HenryQW', 'kt286'], +}; diff --git a/lib/v2/apple/radar.js b/lib/v2/apple/radar.js new file mode 100644 index 000000000..0e4eb469e --- /dev/null +++ b/lib/v2/apple/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'apple.com': { + _name: 'Apple', + support: [ + { + title: '换和维修扩展计划', + docs: 'https://docs.rsshub.app/other.html#apple', + source: ['/:country/service-programs'], + target: '/apple/exchange_repair/:country', + }, + ], + }, +}; diff --git a/lib/v2/apple/router.js b/lib/v2/apple/router.js new file mode 100644 index 000000000..08eee7272 --- /dev/null +++ b/lib/v2/apple/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/exchange_repair/:country?', require('./exchange_repair')); +};