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:
Fatpandac
2022-02-25 00:00:09 +08:00
committed by GitHub
parent f1e7c90c3e
commit 9cb8d5053c
6 changed files with 59 additions and 50 deletions
-3
View File
@@ -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'));
-47
View File
@@ -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,
};
};
+40
View File
@@ -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,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/exchange_repair/:country?': ['metowolf', 'HenryQW', 'kt286'],
};
+13
View File
@@ -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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/exchange_repair/:country?', require('./exchange_repair'));
};