Skip to content

Commit

Permalink
Merge pull request #2505 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 29, 2024
2 parents 954196b + e54a5f1 commit 281f6fb
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 120 deletions.
64 changes: 64 additions & 0 deletions lib/routes/chub/characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/characters',
categories: ['new-media'],
example: '/chub/characters',
name: 'Characters',
maintainers: ['flameleaf'],
handler,
};

async function handler() {
const hostURL = 'https://www.chub.ai/characters';
const apiURL = 'https://api.chub.ai/api/characters/search';
const data = await ofetch(apiURL, {
headers: { Accept: 'application/json' },
query: {
query: '',
first: 200,
page: 1,
sort: 'last_activity_at',
asc: 'false',
include_forks: 'false',
nsfw: 'true',
nsfl: 'true',
nsfw_only: 'false',
require_images: 'false',
require_example_dialogues: 'false',
require_alternate_greetings: 'false',
require_custom_prompt: 'false',
exclude_mine: 'false',
venus: 'true',
chub: 'true',
min_tokens: 50,
require_expressions: 'false',
require_lore: 'false',
mine_first: 'false',
require_lore_embedded: 'false',
require_lore_linked: 'false',
inclusive_or: 'false',
recommended_verified: 'false',
},
});
const nodes = data.nodes;

return {
allowEmpty: true,
title: 'Chub',
link: hostURL,
item: nodes.map((item) => ({
title: item.name,
description: `${item.tagline}<br><br>${item.description}`,
pubDate: parseDate(item.createdAt),
updated: parseDate(item.lastActivityAt),
link: `${hostURL}/${item.fullPath}`,
author: String(item.fullPath.split('/', 1)),
enclosure_url: item.avatar_url,
enclosure_type: `image/webp`,
category: item.topics,
})),
};
}
6 changes: 6 additions & 0 deletions lib/routes/chub/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: 'Chub',
url: 'chub.ai',
};
76 changes: 58 additions & 18 deletions lib/routes/douyu/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,77 @@ export const route: Route = {
},
],
name: '直播间开播',
maintainers: ['DIYgod'],
maintainers: ['DIYgod', 'ChaosTong'],
handler,
};

async function handler(ctx) {
const id = ctx.req.param('id');

const response = await got({
method: 'get',
url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`,
headers: {
Referer: `https://www.douyu.com/${id}`,
},
});
let data;
let item;
let room_thumb;
try {
const response = await got({
method: 'get',
url: `https://www.douyu.com/betard/${id}`,
});

const data = response.data.data;
if (!response.data.room) {
throw new Error('Invalid response');
}

let item;
if (data.online !== 0) {
item = [
{
title: `开播: ${data.room_name}`,
pubDate: new Date(data.start_time).toUTCString(),
guid: data.start_time,
link: `https://www.douyu.com/${id}`,
data = response.data.room;
room_thumb = data.room_pic;

if (data.show_status === 1) {
item =
data.videoLoop === 1
? [
{
title: `视频轮播: ${data.room_name}`,
pubDate: new Date(data.show_time * 1000).toUTCString(),
guid: data.show_time,
link: `https://www.douyu.com/${id}`,
},
]
: [
{
title: `开播: ${data.room_name}`,
pubDate: new Date(data.show_time * 1000).toUTCString(),
guid: data.show_time,
link: `https://www.douyu.com/${id}`,
},
];
}
// make a fallback to the old api
} catch {
const response = await got({
method: 'get',
url: `http://open.douyucdn.cn/api/RoomApi/room/${id}`,
headers: {
Referer: `https://www.douyu.com/${id}`,
},
];
});

data = response.data.data;
room_thumb = data.room_thumb;

if (data.online !== 0) {
item = [
{
title: `开播: ${data.room_name}`,
pubDate: new Date(data.start_time).toUTCString(),
guid: data.start_time,
link: `https://www.douyu.com/${id}`,
},
];
}
}

return {
title: `${data.owner_name}的斗鱼直播间`,
image: room_thumb,
link: `https://www.douyu.com/${id}`,
item,
allowEmpty: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/hellogithub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const sorts = {
};

export const route: Route = {
path: ['/article/:sort?/:id?', '/:sort?/:id?'],
path: ['/article/:sort?/:id?'],
categories: ['programming'],
example: '/hellogithub/article',
parameters: { sort: '排序方式,见下表,默认为 `hot`,即热门', id: '标签 id,可在对应标签页 URL 中找到,默认为全部标签' },
Expand Down Expand Up @@ -61,7 +61,7 @@ async function handler(ctx) {

const $ = load(tagResponse.data);

tag = $('meta[property="og:title"]').attr('content').split(' ').pop();
tag = $('meta[property="og:title"]')?.attr('content')?.split(' ').pop();
buildId = tagResponse.data.match(/"buildId":"(.*?)",/)[1];
}

Expand Down
3 changes: 2 additions & 1 deletion lib/routes/hellogithub/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const types = {

export const route: Route = {
path: ['/ranking/:type?', '/report/:type?'],
name: 'Unknown',
example: '/hellogithub/ranking',
name: '榜单报告',
maintainers: ['moke8', 'nczitzk'],
handler,
description: `| 编程语言 | 服务器 | 数据库 |
Expand Down
63 changes: 39 additions & 24 deletions lib/routes/hellogithub/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,68 @@ const md = MarkdownIt({
html: true,
});
import { load } from 'cheerio';
import cache from '@/utils/cache';
import { config } from '@/config';

art.defaults.imports.render = function (string) {
return md.render(string);
};

export const route: Route = {
path: ['/month', '/volume'],
name: 'Unknown',
maintainers: ['moke8', 'nczitzk'],
example: '/hellogithub/volume',
name: '月刊',
maintainers: ['moke8', 'nczitzk', 'CaoMeiYouRen'],
handler,
};

async function handler() {
async function handler(ctx) {
const limit: number = Number.parseInt(ctx.req.query('limit')) || 10;
const rootUrl = 'https://hellogithub.com';
const apiUrl = 'https://api.hellogithub.com/v1/periodical/';

const periodicalResponse = await got({
method: 'get',
url: apiUrl,
});
const current = periodicalResponse.data.volumes[0].num;
const currentUrl = `${rootUrl}/periodical/volume/${current}`;
const buildResponse = await got({
method: 'get',
url: currentUrl,
});
const volumes = periodicalResponse.data.volumes.slice(0, limit);

const $ = load(buildResponse.data);
const items = await Promise.all(
volumes.map(async (volume) => {
const current = volume.num;
const currentUrl = `${rootUrl}/periodical/volume/${current}`;
const key = `hellogithub:${currentUrl}`;
return await cache.tryGet(
key,
async () => {
const buildResponse = await got({
method: 'get',
url: currentUrl,
});

const text = $('#__NEXT_DATA__').text();
const response = JSON.parse(text);
const data = response.props;
const id = data.pageProps.volume.current_num;
const $ = load(buildResponse.data);

const items = [
{
title: `No.${id}`,
link: `${rootUrl}/periodical/volume/${id}`,
description: art(path.join(__dirname, 'templates/volume.art'), {
data: data.pageProps.volume.data,
}),
},
];
const text = $('#__NEXT_DATA__').text();
const response = JSON.parse(text);
const data = response.props;
const id = data.pageProps.volume.current_num;
return {
title: `《HelloGitHub》第 ${id} 期`,
link: `${rootUrl}/periodical/volume/${id}`,
description: art(path.join(__dirname, 'templates/volume.art'), {
data: data.pageProps.volume.data,
}),
};
},
config.cache.routeExpire,
false
);
})
);

return {
title: 'HelloGithub - 月刊',
link: currentUrl,
link: 'https://hellogithub.com/periodical',
item: items,
};
}
4 changes: 2 additions & 2 deletions lib/routes/sjtu/yzb/zkxx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async function handler(ctx) {
.toArray()
.map((elem) => ({
link: new URL(elem.attribs.href, pageUrl).href,
title: elem.attribs.title,
pubDate: parseDate($(elem.next).text().trim()),
title: $(elem).text(),
pubDate: parseDate($(elem.next?.next).text().trim()),
})),
};
}
Loading

0 comments on commit 281f6fb

Please sign in to comment.