Skip to content

Commit

Permalink
Merge pull request #1341 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Apr 7, 2024
2 parents 0cdb9cb + cb69f50 commit 0b3a642
Show file tree
Hide file tree
Showing 44 changed files with 1,145 additions and 428 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ router.get('/qutoutiao/category/:cid', lazyloadRouteHandler('./routes/qutoutiao/
// router.get('/bbc/:site?/:channel?', lazyloadRouteHandler('./routes/bbc/index'));

// 看雪
router.get('/pediy/topic/:category?/:type?', lazyloadRouteHandler('./routes/pediy/topic'));
// router.get('/pediy/topic/:category?/:type?', lazyloadRouteHandler('./routes/pediy/topic'));

// 老司机
router.get('/laosiji/hot', lazyloadRouteHandler('./routes/laosiji/hot'));
Expand Down
117 changes: 0 additions & 117 deletions lib/routes-deprecated/pediy/topic.js

This file was deleted.

27 changes: 0 additions & 27 deletions lib/routes-deprecated/pediy/utils.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/routes/12371/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '共产党员网',
url: 'www.12371.cn',
categories: ['government'],
};
64 changes: 64 additions & 0 deletions lib/routes/12371/zxfb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import got from '@/utils/got';
import * as cheerio from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import cache from '@/utils/cache';

import { Route } from '@/types';

const handler = async (ctx) => {
const { category = 'zxfb' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15;

const rootUrl = 'https://www.12371.cn/';
const currentUrl = `${rootUrl}${category}/`;
const response = await got(currentUrl);

const $ = cheerio.load(response.data);

const pattern = /item=(\[{.*?}]);/;
const newsList = JSON.parse($('script[language="javascript"]').text().match(pattern)?.[1].replaceAll("'", '"') || '[]');

const topNewsList = newsList.slice(0, limit).map((item) => ({
title: item.title,
pubDate: timezone(parseDate(item.brief, 'YYYY-MM-DD HH:mm:ss'), 8),
link: item.link_add,
}));

const items = await Promise.all(
topNewsList.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link);
const $ = cheerio.load(detailResponse.data);

item.description = $('.word').html();

return item;
})
)
);

return {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

export const route: Route = {
path: '/:category?',
example: '/12371/zxfb',
parameters: { category: '新闻分类名,预设 `zxfb`' },
radar: [
{
source: ['www.12371.cn/:category'],
},
],
name: '最新发布',
maintainers: ['zvrr'],
handler,
url: 'www.12371.cn',
description: `| 最新发布 |
| :------: |
| zxfb |`,
};
6 changes: 6 additions & 0 deletions lib/routes/51cto/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '51CTO',
url: '51cto.com',
};
52 changes: 52 additions & 0 deletions lib/routes/51cto/recommend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import got from '@/utils/got';
import { getToken, sign } from './utils';

export const route: Route = {
path: '/index/recommend',
categories: ['programming'],
example: '/51cto/index/recommend',
radar: [
{
source: ['51cto.com/'],
},
],
name: '推荐',
maintainers: ['cnkmmk'],
handler,
url: '51cto.com/',
};

async function handler(ctx) {
const url = 'https://api-media.51cto.com';
const requestPath = 'index/index/recommend';
const token = (await getToken()) as string;
const timestamp = Date.now();
const params = {
page: 1,
page_size: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50,
limit_time: 0,
name_en: '',
};
const response = await got(`${url}/${requestPath}`, {
searchParams: {
...params,
timestamp,
token,
sign: sign(requestPath, params, timestamp, token),
},
});
const list = response.data.data.data.list;
return {
title: '51CTO',
link: 'https://www.51cto.com/',
description: '51cto - 推荐',
item: list.map((item) => ({
title: item.title,
link: item.url,
pubDate: parseDate(item.pubdate, +8),
description: item.abstract,
})),
};
}
21 changes: 21 additions & 0 deletions lib/routes/51cto/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
import md5 from '@/utils/md5';

export const getToken = () =>
cache.tryGet(
'51cto:token',
async () => {
const response = await ofetch('https://api-media.51cto.com/api/token-get');
return response.data.data.token;
},
3600,
false
);

export const sign = (requestPath: string, payload: Record<string, any> = {}, timestamp: number, token: string) => {
payload.timestamp = timestamp;
payload.token = token;
const sortedParams = Object.keys(payload).sort();
return md5(md5(requestPath) + md5(sortedParams + md5(token) + timestamp));
};
2 changes: 1 addition & 1 deletion lib/routes/apnews/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function handler(ctx) {
const $ = load(response.data);

const items = await Promise.all(
$('.PagePromo-content bsp-custom-headline')
$(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline')
.get()
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : Infinity)
.map((e) => ({
Expand Down
2 changes: 2 additions & 0 deletions lib/routes/bilibili/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ async function handler(ctx) {
link: `https://space.bilibili.com/${uid}/dynamic`,
description: `${author} 的 bilibili 动态`,
image: face,
logo: face,
icon: face,
item: rssItems,
};
}
46 changes: 46 additions & 0 deletions lib/routes/binance/launchpool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/launchpool',
categories: ['finance'],
example: '/binance/launchpool',
radar: [
{
source: ['binance.com/:lang/support/announcement'],
},
],
name: 'Binance数字货币及交易对上新',
maintainers: ['zhenlohuang'],
handler,
};

async function handler() {
const baseUrl = 'https://www.binance.com/zh-CN/support/announcement';
const url = `${baseUrl}/数字货币及交易对上新?c=48&navId=48`;

const response = await got({
url,
headers: {
Referer: 'https://www.binance.com/',
},
});

const $ = load(response.data);
const appData = JSON.parse($('#__APP_DATA').text());
const articles = appData.appState.loader.dataByRouteId.d969.catalogs.find((catalog) => catalog.catalogId === 48).articles.filter((article) => article.title.includes('币安新币挖矿上线'));

return {
title: 'Binance | 数字货币及交易对上新',
link: url,
description: '数字货币及交易对上新',
item: articles.map((item) => ({
title: item.title,
link: `${baseUrl}/${item.code}`,
description: item.title,
pubDate: parseDate(item.releaseDate),
})),
};
}
6 changes: 6 additions & 0 deletions lib/routes/binance/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Binance',
url: 'binance.com',
};
Loading

0 comments on commit 0b3a642

Please sign in to comment.