fix(route): clickme (#11689)

This commit is contained in:
Tony 2023-01-25 04:50:04 -08:00 committed by GitHub
parent 54aea54dd6
commit 3883948139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 78 deletions

View File

@ -95,7 +95,7 @@ pageClass: routes
### 文章
<Route author="hoilc" example="/clickme/default/category/beauty" path="/clickme/:site/:grouping/:name" :paramsDesc="['站点, `default`为普通站, `r18`为成人站, 其它值默认为普通站','分组方式, `category`为分类, `tag`为标签, 其他值默认为分类','分类名或标签名, 分类名为英文, 可以在分类 URL 中找到']" />
<Route author="hoilc" example="/clickme/default/category/beauty" path="/clickme/:site/:grouping/:name" :paramsDesc="['站点`default`为普通站,`r18`为成人站,其它值默认为普通站','分组方式,`category`为分类,`tag`为标签,其他值默认为分类','分类名或标签名,分类名为英文,可以在分类 URL 中找到']" radar="1"/>
## Darwin Awards

View File

@ -2223,7 +2223,7 @@ router.get('/gov/cnca/hydt', lazyloadRouteHandler('./routes/gov/cnca/hydt'));
router.get('/gov/cnca/zxtz', lazyloadRouteHandler('./routes/gov/cnca/zxtz'));
// clickme
router.get('/clickme/:site/:grouping/:name', lazyloadRouteHandler('./routes/clickme'));
// router.get('/clickme/:site/:grouping/:name', lazyloadRouteHandler('./routes/clickme'));
// 文汇报
router.get('/whb/:category', lazyloadRouteHandler('./routes/whb/zhuzhan'));

View File

@ -1,76 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const site = ctx.params.site === 'r18' ? 'r18' : '';
const grouping = ctx.params.grouping === 'tag' ? 'tag' : 'category';
const name = ctx.params.name;
const url = `https://${site ? 'r18.' : ''}clickme.net/${grouping.slice(0, 1)}/${encodeURIComponent(name)}`;
const response = await got({
method: 'post',
url: 'https://api.clickme.net/article/list?key=clickme',
headers: {
Referer: url,
},
form: {
articleType: site ? 'r18' : 'article',
subtype: grouping,
subtypeSlug: name,
device: '',
limit: 10,
page: 1,
},
});
const category_name = name === 'new' ? '最新' : response.data.data.items[0].categoryName[0].name;
const displayed_name = grouping === 'tag' ? name : category_name;
const list = response.data.data.items;
const parseContent = (htmlString) => {
const $ = cheerio.load(htmlString);
const content = $('.article-detail-content');
return {
description: content.html(),
};
};
const out = await Promise.all(
list.map(async (item) => {
const link = item.url;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const rssitem = {
title: item.title,
link,
author: item.userNick,
pubDate: new Date(item.date * 1000),
};
try {
const response = await got.get(link);
const result = parseContent(response.data);
if (!result.description) {
return Promise.resolve('');
}
rssitem.description = result.description;
} catch (err) {
return Promise.resolve('');
}
ctx.cache.set(link, JSON.stringify(rssitem));
return Promise.resolve(rssitem);
})
);
ctx.state.data = {
title: `ClickMe ${site ? 'R18 ' : ''}- ${displayed_name}`,
link: url,
item: out.filter((item) => item !== ''),
};
};

56
lib/v2/clickme/index.js Normal file
View File

@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const site = ctx.params.site === 'r18' ? 'r18' : '';
const grouping = ctx.params.grouping === 'tag' ? 'tag' : 'category';
const name = ctx.params.name;
const url = `https://${site ? 'r18.' : ''}clickme.net/${grouping.substring(0, 1)}/${encodeURIComponent(name)}`;
const { data: response } = await got.post('https://api.clickme.net/article/list', {
headers: {
Referer: url,
},
searchParams: {
key: 'clickme',
},
form: {
articleType: site ? 'r18' : 'article',
subtype: grouping,
subtypeSlug: name,
device: '',
limit: 18,
page: 1,
},
});
const category_name = name === 'new' ? '最新' : response.data.items[0].categoryName[0].name;
const displayed_name = grouping === 'tag' ? name : category_name;
const list = response.data.items.map((item) => ({
title: item.title,
link: item.url.replace('http://', 'https://'),
author: item.userNick,
pubDate: parseDate(item.date, 'X'),
category: [...item.categoryName.map((item) => item.name), ...item.tags],
}));
const out = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got.get(item.link);
const $ = cheerio.load(data);
item.description = $('.article-detail-content').html();
return item;
})
)
);
ctx.state.data = {
title: `ClickMe ${site ? 'R18 ' : ''}- ${displayed_name}`,
link: url,
item: out,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:site/:grouping/:name': ['hoilc'],
};

21
lib/v2/clickme/radar.js Normal file
View File

@ -0,0 +1,21 @@
module.exports = {
'clickme.net': {
_name: 'ClickMe',
'.': [
{
title: '文章',
docs: 'https://docs.rsshub.app/other.html#clickme',
source: ['/:grouping/:name'],
target: (params) => `/clickme/default/${params.grouping === 't' ? 'tag' : 'category'}/${params.name}`,
},
],
r18: [
{
title: '文章',
docs: 'https://docs.rsshub.app/other.html#clickme',
source: ['/:grouping/:name'],
target: (params) => `/clickme/r18/${params.grouping === 't' ? 'tag' : 'category'}/${params.name}`,
},
],
},
};

3
lib/v2/clickme/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:site/:grouping/:name', require('./index'));
};