Skip to content

Commit

Permalink
Merge pull request #1364 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 23, 2024
2 parents 3379c5a + 41c6861 commit 12d702c
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 24 deletions.
88 changes: 88 additions & 0 deletions lib/routes/colamanga/manga.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Route } from '@/types';
import puppeteer from '@/utils/puppeteer';

import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { Context } from 'hono';
import logger from '@/utils/logger';

const domain = 'www.colamanga.com';

export const route: Route = {
path: '/:id',
parameters: { id: '漫画id' },
name: 'Manga',
maintainers: ['machsix'],
example: '/colamanga/manga-qq978758',
categories: ['anime'],
radar: [
{
source: [`${domain}/:id/`],
target: '/:id',
},
],
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
handler,
};

function shift_date(date, days) {
const result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}

async function handler(ctx: Context) {
const id = ctx.req.param('id');
const url = `https://${domain}/${id}`;

const browser = await puppeteer();

const page = await browser.newPage();

await page.setRequestInterception(true);

page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});

logger.http(`Requesting ${url}`);
await page.goto(url, {
// 指定页面等待载入的时间
waitUntil: 'domcontentloaded',
});

const response = await page.content();
browser.close();

const $ = load(response);

const book_name = $("meta[property='og:comic:book_name']").attr('content');
const updateDateAttr = $("meta[property='og:comic:update_time']").attr('content');
const updateDate = updateDateAttr ? timezone(parseDate(updateDateAttr)) : timezone(new Date());

const author = $("span:contains('作者')").parent().contents().eq(1).text();
// const cover = $(".fed-deta-images a").attr('data-original');
const items = $('.all_data_list >ul>li>a')
.map((i, elem) => ({
title: `${book_name} ${$(elem).text()}`,
link: elem.attribs.href,
description: $('.fed-part-esan').text(),
author,
pubDate: shift_date(updateDate, -7 * i),
}))
.get();

return {
title: book_name || 'Unknown Manga',
link: url,
item: items,
};
}
9 changes: 9 additions & 0 deletions lib/routes/colamanga/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'COLAMANGA',
url: 'www.colamanga.com',
zh: {
name: '可乐漫画',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '中国人民银行',
url: 'kjt.ah.gov.cn',
url: 'pbc.gov.cn',
description: `<details>
<summary>*业务咨询* 和 *投诉建议* 可用的站点参数</summary>
Expand Down
15 changes: 13 additions & 2 deletions lib/routes/ncu/jwc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ async function handler() {
const baseUrl = 'https://jwc.ncu.edu.cn';
const response = await got(baseUrl);
const $ = load(response.body);
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1;

const list = $('.box3 .inner ul.img-list li');

return {
title: '南昌大学教务处',
link: baseUrl,
description: '南昌大学教务处',

item:
list &&
list.toArray().map((item) => {
Expand All @@ -46,12 +50,19 @@ async function handler() {
const date = el.text().split('】')[0].replace('【', '').trim();
const title = linkEl.attr('title');
const link = `${baseUrl}/${linkEl.attr('href')}`;
const month = date.slice(0, 2);

const newsDate = parseDate(date, 'MM-DD');
const newsMonth = newsDate.getMonth() + 1;

// If the news month is greater than the current month, subtract 1 from the year
const year = newsMonth > currentMonth ? currentYear - 1 : currentYear;

newsDate.setFullYear(year);

return {
title,
link,
pubDate: parseDate(date, 'MM-DD').setFullYear(month < 6 ? new Date().getFullYear() - 1 : new Date().getFullYear()),
pubDate: newsDate,
};
}),
};
Expand Down
12 changes: 12 additions & 0 deletions lib/routes/telegram/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ async function handler(ctx) {
);

const $ = load(data);

/*
* Since 2024/4/20, t.me/s/ mistakenly have every '&' in **hyperlinks** replaced by '&amp;'.
* The characteristic of a hyperlink is [onclick] (pop-up confirmation), which is not present in ordinary links.
* This is a workaround to fix the issue until Telegram fixes it.
*/
$('a[onclick][href]').each((_, elem) => {
const $elem = $(elem);
const href = $elem.attr('href');
href && $elem.attr('href', href.replaceAll('&amp;', '&'));
});

const list = includeServiceMsg
? $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.tme_no_messages_found))') // exclude 'no posts found' messages
: $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.service_message,.tme_no_messages_found))'); // also exclude service messages
Expand Down
9 changes: 8 additions & 1 deletion lib/routes/wechat/tgchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ async function handler(ctx) {

const pubDate = new Date(item.find('.tgme_widget_message_date time').attr('datetime')).toUTCString();

/*
* Since 2024/4/20, t.me/s/ mistakenly have every '&' in **hyperlinks** replaced by '&amp;'.
* wechat-mp will take care of this, so no need to fix it here.
* However, once the bug is eventually fixed, all guid will be changed again.
* Considering that this is almost certain to happen, let's break guid consistency now by using
* normalized URL from wechat-mp as guid to avoid similar issues in the future.
*/
const single = {
title,
pubDate,
link,
guid: link,
// guid: link,
};

if (link !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions lib/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Unknown paragraph
const formData = await request.formData();
return HttpResponse.json({
test: formData.get('test'),
req: { headers: Object.fromEntries(request.headers.entries()) },
});
}),
http.post(`http://rsshub.test/json-post`, async ({ request }) => {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/got.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ describe('got', () => {
test: 'rsshub',
},
});
expect(response.body).toBe('{"test":"rsshub"}');
expect(response.body).toContain('"test":"rsshub"');
expect(response.data.test).toBe('rsshub');
expect(response.data.req.headers['content-type']).toBe('application/x-www-form-urlencoded');
});

it('json-post', async () => {
Expand Down
7 changes: 2 additions & 5 deletions lib/utils/got.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ const getFakeGot = (defaultOptions?: any) => {
delete options.json;
}
if (options?.form && !options.body) {
const body = new FormData();
for (const key in options.form) {
body.append(key, options.form[key]);
}
options.body = body;
options.body = new URLSearchParams(options.form as Record<string, string>).toString();
if (!options.headers) {
options.headers = {};
}
options.headers['content-type'] = 'application/x-www-form-urlencoded';
delete options.form;
}
if (options?.searchParams) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"uuid": "9.0.1",
"winston": "3.13.0",
"xxhash-wasm": "1.0.2",
"zod": "3.23.0"
"zod": "3.23.3"
},
"devDependencies": {
"@babel/preset-env": "7.24.4",
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12d702c

Please sign in to comment.