fix(route): apple/exchange_repair refactor to V2 (#9176)
* fix(route): apple/exchange_repair refactor to V2 * fix(route): add radar.js * fix: remove legacy url.resolve use tryGet
This commit is contained in:
@@ -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'));
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/exchange_repair/:country?': ['metowolf', 'HenryQW', 'kt286'],
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/exchange_repair/:country?', require('./exchange_repair'));
|
||||
};
|
||||
Reference in New Issue
Block a user