feat(route): add 爱范儿快讯 (#18024)
* feat(route): add 爱范儿快讯 * chore: remove deprecated file * fix: deepscan issue ---------
This commit is contained in:
+1
-1
@@ -294,7 +294,7 @@ router.get('/fzu_min/:type', lazyloadRouteHandler('./routes/universities/fzu/new
|
||||
router.get('/xmu/aero/:type', lazyloadRouteHandler('./routes/universities/xmu/aero'));
|
||||
|
||||
// ifanr
|
||||
router.get('/ifanr/:channel?', lazyloadRouteHandler('./routes/ifanr/index'));
|
||||
// router.get('/ifanr/:channel?', lazyloadRouteHandler('./routes/ifanr/index'));
|
||||
|
||||
// IPSW.me
|
||||
// router.get('/ipsw/index/:ptype/:pname', lazyloadRouteHandler('./routes/ipsw/index'));
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let host = 'https://www.ifanr.com';
|
||||
|
||||
let channel;
|
||||
if (ctx.params.channel) {
|
||||
channel = ctx.params.channel.toLowerCase();
|
||||
channel = channel.split('-').join('/');
|
||||
|
||||
// 兼容旧版路由
|
||||
host = channel === 'appso' ? `${host}/app` : `${host}/${channel}`;
|
||||
} else {
|
||||
host = `${host}/app`;
|
||||
channel = 'app';
|
||||
}
|
||||
|
||||
const response = await got.get(host);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let list;
|
||||
switch (channel) {
|
||||
case 'dasheng':
|
||||
list = $('#articles-collection')
|
||||
.find('.c-bricks__brick a.c-dasheng')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
break;
|
||||
default:
|
||||
list = $('#articles-collection')
|
||||
.find('.article-item .article-info h3 a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
break;
|
||||
}
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl) => {
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return JSON.parse(cache);
|
||||
}
|
||||
|
||||
const response = await got.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const item = {
|
||||
title: $('.c-single-normal__title').text(),
|
||||
link: itemUrl,
|
||||
author: $('.c-card-author__name').text(),
|
||||
description: $('article').html(),
|
||||
pubDate: new Date($('.c-article-header-meta__time').attr('data-timestamp') * 1000),
|
||||
};
|
||||
// "大声" 标题
|
||||
if (/^https?:\/\/www\.ifanr\.com\/dasheng\/.*$/.test(itemUrl)) {
|
||||
item.title = $('.c-dasheng_header__title').text();
|
||||
}
|
||||
|
||||
ctx.cache.set(itemUrl, JSON.stringify(item));
|
||||
return item;
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `iFanr - ${$('h1.c-archive-header__title').text()}:${$('div.c-archive-header__desc').text()}`,
|
||||
link: host,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
import { type CheerioAPI, load } from 'cheerio';
|
||||
import { type Context } from 'hono';
|
||||
|
||||
import { type DataItem, type Route, type Data, ViewType } from '@/types';
|
||||
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '20', 10);
|
||||
|
||||
const baseUrl: string = 'https://www.ifanr.com';
|
||||
const apiBaseUrl: string = 'https://sso.ifanr.com';
|
||||
const targetUrl: string = new URL('digest', baseUrl).href;
|
||||
const apiUrl: string = new URL('api/v5/wp/buzz', apiBaseUrl).href;
|
||||
|
||||
const response = await ofetch(apiUrl, {
|
||||
query: {
|
||||
limit,
|
||||
offset: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const targetResponse = await ofetch(targetUrl);
|
||||
const $: CheerioAPI = load(targetResponse);
|
||||
const language: string = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
const items: DataItem[] = response.objects.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.post_title;
|
||||
const description: string = item.post_content;
|
||||
const pubDate: number | string = item.created_at;
|
||||
const linkUrl: string = `digest/${item.post_id}`;
|
||||
const guid: string = `ifanr-digest-${item.post_id}`;
|
||||
const updated: number | string = item.updated_at ?? pubDate;
|
||||
|
||||
const processedItem: DataItem = {
|
||||
title,
|
||||
description,
|
||||
pubDate: pubDate ? parseDate(pubDate, 'X') : undefined,
|
||||
link: new URL(linkUrl, baseUrl).href,
|
||||
guid,
|
||||
id: guid,
|
||||
content: {
|
||||
html: description,
|
||||
text: item.post_content ?? description,
|
||||
},
|
||||
updated: updated ? parseDate(updated) : undefined,
|
||||
language,
|
||||
_extra: {
|
||||
links: [
|
||||
{
|
||||
url: item.buzz_original_url,
|
||||
type: 'via',
|
||||
content_html: item.post_content,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
return processedItem;
|
||||
});
|
||||
|
||||
const title: string = $('title').text();
|
||||
|
||||
return {
|
||||
title,
|
||||
description: title,
|
||||
link: targetUrl,
|
||||
item: items,
|
||||
allowEmpty: true,
|
||||
image: $('img.c-header-navbar__logo').attr('src'),
|
||||
author: $('meta[property="og:site_name"]').attr('content'),
|
||||
language,
|
||||
id: $('meta[property="og:url"]').attr('content'),
|
||||
};
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/digest',
|
||||
name: '快讯',
|
||||
url: 'www.ifanr.com',
|
||||
maintainers: ['nczitzk'],
|
||||
handler,
|
||||
example: '/ifanr/digest',
|
||||
parameters: undefined,
|
||||
description: undefined,
|
||||
categories: ['new-media'],
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportRadar: true,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['www.ifanr.comdigest'],
|
||||
target: '/digest',
|
||||
},
|
||||
],
|
||||
view: ViewType.Articles,
|
||||
};
|
||||
Reference in New Issue
Block a user