Skip to content

Commit

Permalink
fix(route): duplicate-object-key (DIYgod#15494)
Browse files Browse the repository at this point in the history
* fix(route): duplicate-object-key

* fix: split routes

* fix: split routes

* fix: typo
  • Loading branch information
TonyRL authored May 6, 2024
1 parent 7892a54 commit 936e703
Show file tree
Hide file tree
Showing 41 changed files with 495 additions and 420 deletions.
23 changes: 23 additions & 0 deletions lib/routes/cnbeta/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Route } from '@/types';
import { handler } from './common';

export const route: Route = {
name: '分类',
path: ['/category/:id'],
example: '/cnbeta/category/movie',
maintainers: ['nczitzk'],
parameters: {
id: '分类 id,可在对应分类页的 URL 中找到',
},
radar: [
{
source: ['cnbeta.com.tw/category/:id'],
target: (params) => `/cnbeta/category/${params.id.replace('.htm', '')}`,
},
],
handler,
url: 'cnbeta.com.tw',
description: `| 影视 | 音乐 | 游戏 | 动漫 | 趣闻 | 科学 | 软件 |
| ----- | ----- | ---- | ----- | ----- | ------- | ---- |
| movie | music | game | comic | funny | science | soft |`,
};
18 changes: 1 addition & 17 deletions lib/routes/cnbeta/type.ts → lib/routes/cnbeta/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
Expand All @@ -7,22 +6,7 @@ import { parseDate } from '@/utils/parse-date';

import { rootUrl, ProcessItems } from './utils';

export const route: Route = {
path: ['/:type/:id', '/'],
radar: [
{
source: ['cnbeta.com.tw/'],
target: '',
},
],
name: 'Unknown',
maintainers: [],
handler,
url: 'cnbeta.com.tw/',
url: 'cnbeta.com.tw/',
};

async function handler(ctx) {
export async function handler(ctx) {
const { type, id } = ctx.req.param();

const currentUrl = type ? `${rootUrl}/${type}/${id}.htm` : rootUrl;
Expand Down
16 changes: 16 additions & 0 deletions lib/routes/cnbeta/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Route } from '@/types';
import { handler } from './common';

export const route: Route = {
name: '头条资讯',
path: ['/'],
example: '/cnbeta',
radar: [
{
source: ['cnbeta.com.tw/'],
},
],
maintainers: ['kt286', 'HaitianLiu', 'nczitzk'],
handler,
url: 'cnbeta.com.tw',
};
1 change: 1 addition & 0 deletions lib/routes/cnbeta/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'cnBeta.COM',
url: 'cnbeta.com.tw',
categories: ['new-media'],
};
23 changes: 23 additions & 0 deletions lib/routes/cnbeta/topics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Route } from '@/types';
import { handler } from './common';

export const route: Route = {
name: '主题',
path: ['/topics/:id'],
example: '/cnbeta/topics/453',
maintainers: ['cczhong11', 'nczitzk'],
parameters: {
id: '主题 id,可在对应主题页的 URL 中找到',
},
radar: [
{
source: ['cnbeta.com.tw/topics/:id'],
target: (params) => `/cnbeta/topics/${params.id.replace('.htm', '')}`,
},
],
handler,
url: 'cnbeta.com.tw',
description: `::: tip
完整的主题列表参见 [主题列表](https://www.cnbeta.com.tw/topics.htm)
:::`,
};
2 changes: 0 additions & 2 deletions lib/routes/cnblogs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export const route: Route = {
url: 'www.cnblogs.com/pick',
description: `在博客园主页的分类出可查看所有类型。例如,go 的分类地址为: \`https://www.cnblogs.com/cate/go/\`, 则: [\`/cnblogs/cate/go\`](https://rsshub.app/cnblogs/cate/go)`,
url: 'www.cnblogs.com/aggsite/headline',
url: 'www.cnblogs.com/aggsite/topviews',
url: 'www.cnblogs.com/aggsite/topdiggs',
};

async function handler(ctx) {
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/cnki/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import utils from './utils';
import { ProcessItem } from './utils';

const rootUrl = 'https://kns.cnki.net';

Expand Down Expand Up @@ -70,7 +70,7 @@ async function handler(ctx) {
};
});

const items = await Promise.all(list.map((item) => cache.tryGet(item.link, () => utils.ProcessItem(item))));
const items = await Promise.all(list.map((item) => cache.tryGet(item.link, () => ProcessItem(item))));

return {
title: `知网 ${authorName} ${companyName}`,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/cnki/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ const ProcessItem = async (item) => {
return item;
};

export default { ProcessItem };
export { ProcessItem };
4 changes: 2 additions & 2 deletions lib/routes/creative-comic/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cache from '@/utils/cache';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
import { getUuid, getBook, getChapter, getChapters, getImgEncrypted, getImgKey, decrypt, getRealKey, siteHost } from './utils';
import { getUuid, getBook, getChapter, getChapters, getImgEncrypted, getImgKey, decrypt, getRealKey, apiHost } from './utils';

export const route: Route = {
path: '/book/:id/:coverOnly?/:quality?',
Expand Down Expand Up @@ -62,7 +62,7 @@ async function handler(ctx) {
const realKey = getRealKey(imgKey);
const encrypted = await getImgEncrypted(p.id, quality);

return cache.tryGet(`${siteHost}/fs/chapter_content/encrypt/${p.id}/${quality}`, () => decrypt(encrypted, realKey));
return cache.tryGet(`${apiHost}/fs/chapter_content/encrypt/${p.id}/${quality}`, () => decrypt(encrypted, realKey));
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/creative-comic/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ const getRealKey = (imgKey, token = DEFAULT_TOKEN) => {
};
};

export { getBook, getChapter, getChapters, getImgEncrypted, getImgKey, getUuid, decrypt, token2Key, getRealKey };
export { apiHost, getBook, getChapter, getChapters, getImgEncrypted, getImgKey, getUuid, decrypt, token2Key, getRealKey };
7 changes: 3 additions & 4 deletions lib/routes/darwinawards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import got from '@/utils/got';
import { load } from 'cheerio';

export const route: Route = {
path: ['/all', '/'],
name: 'Award Winners',
example: '/darwinawards',
path: '/',
radar: [
{
source: ['darwinawards.com/darwin', 'darwinawards.com/'],
target: '',
},
],
name: 'Unknown',
maintainers: ['zoenglinghou', 'nczitzk'],
handler,
url: 'darwinawards.com/darwin',
url: 'darwinawards.com/darwin',
};

async function handler() {
Expand Down
1 change: 1 addition & 0 deletions lib/routes/darwinawards/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Darwin Awards',
url: 'darwinawards.com',
categories: ['other'],
};
105 changes: 0 additions & 105 deletions lib/routes/dnaindia/category.ts
Original file line number Diff line number Diff line change
@@ -1,105 +0,0 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import logger from '@/utils/logger';

export const route: Route = {
path: ['/:category', '/topic/:topic'],
categories: ['traditional-media'],
example: '/dnaindia/headlines',
parameters: { category: 'Find it in the URL, or tables below' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['dnaindia.com/:category'],
},
],
name: 'News',
maintainers: ['Rjnishant530'],
handler,
description: `Topics:
| DNA verified |
| ------------ |
| dna-verified |
:::tip Topic
The URL of the form \`https://www.dnaindia.com/topic/dna-verified\` demonstrates the utilization of the subdomain \`topic\`
:::`,
description: `Categories:
| Headlines | Explainer | India | Entertainment | Sports | Viral | Lifestyle | Education | Business | World |
| --------- | --------- | ----- | ------------- | ------ | ----- | --------- | --------- | -------- | ----- |
| headlines | explainer | india | entertainment | sports | viral | lifestyle | education | business | world |`,
};

async function handler(ctx) {
const { category, topic } = ctx.req.param();
const baseUrl = 'https://www.dnaindia.com';
let route;
if (category) {
route = `/${category}`;
} else if (topic) {
route = `/topic/${topic}`;
} else {
logger.error('Invalid URL');
}
const { data: response } = await got(`${baseUrl}${route}`);
const $ = load(response);

const listItems = $('div.col-lg-6 div.list-news')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('div.explainer-subtext a');
return {
title: a.text(),
link: `${baseUrl}${a.attr('href')}`,
};
});

const items = await Promise.all(
listItems.map((item) =>
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = load(response);
item.itunes_item_image = $('div.article-img img').attr('src');
item.category = $('div.tags ul li')
.toArray()
.map((item) => $(item).find('a').text());
const time = $('p.dna-update').text().split('Updated:')[1];
item.pubDate = timezone(parseDate(time, 'MMMDD,YYYY,hh:mmA'), +5.5);
item.author = 'DNA Web Team';
item.description = $('div.article-description')
.clone()
.children('div')
.remove()
.end()
.toArray()
.map((element) => $(element).html())
.join('');
return item;
})
)
);

return {
title: 'DNA India',
link: baseUrl,
item: items,
description: 'Latest News on dnaIndia.com',
logo: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico',
icon: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico',
language: 'en-us',
};
}
68 changes: 68 additions & 0 deletions lib/routes/dnaindia/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import logger from '@/utils/logger';

export async function handler(ctx) {
const { category, topic } = ctx.req.param();
const baseUrl = 'https://www.dnaindia.com';
let route;
if (category) {
route = `/${category}`;
} else if (topic) {
route = `/topic/${topic}`;
} else {
logger.error('Invalid URL');
}
const link = `${baseUrl}${route}`;
const { data: response } = await got(link);
const $ = load(response);

const listItems = $('div.col-lg-6 div.list-news')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('div.explainer-subtext a');
return {
title: a.text(),
link: `${baseUrl}${a.attr('href')}`,
};
});

const items = await Promise.all(
listItems.map((item) =>
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = load(response);
item.itunes_item_image = $('div.article-img img').attr('src');
item.category = $('div.tags ul li')
.toArray()
.map((item) => $(item).find('a').text());
const time = $('p.dna-update').text().split('Updated:')[1];
item.pubDate = timezone(parseDate(time, 'MMMDD,YYYY,hh:mmA'), +5.5);
item.author = 'DNA Web Team';
item.description = $('div.article-description')
.clone()
.children('div')
.remove()
.end()
.toArray()
.map((element) => $(element).html())
.join('');
return item;
})
)
);

return {
title: 'DNA India',
link,
item: items,
description: 'Latest News on dnaIndia.com',
logo: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico',
icon: 'https://cdn.dnaindia.com/sites/all/themes/dnaindia/favicon-1016.ico',
language: 'en-us',
};
}
1 change: 1 addition & 0 deletions lib/routes/dnaindia/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'DNA India',
url: 'dnaindia.com',
categories: ['traditional-media'],
};
24 changes: 24 additions & 0 deletions lib/routes/dnaindia/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Route } from '@/types';
import { handler } from './common';

export const route: Route = {
name: 'News',
maintainers: ['Rjnishant530'],
path: ['/:category'],
example: '/dnaindia/headlines',
parameters: {
category: 'Find it in the URL, or tables below',
},
radar: [
{
source: ['www.dnaindia.com/:category'],
},
],
handler,
url: 'www.dnaindia.com',
description: `Categories:
| Headlines | Explainer | India | Entertainment | Sports | Viral | Lifestyle | Education | Business | World |
| --------- | --------- | ----- | ------------- | ------ | ----- | --------- | --------- | -------- | ----- |
| headlines | explainer | india | entertainment | sports | viral | lifestyle | education | business | world |`,
};
Loading

0 comments on commit 936e703

Please sign in to comment.