Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/middleware/empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { MiddlewareHandler } from 'hono';

const emptyMiddleware: MiddlewareHandler = async (ctx, next) => {
await next();
};

export default emptyMiddleware;
7 changes: 4 additions & 3 deletions lib/pkg.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { sValidator } from '@hono/standard-validator';
import type { Handler, Hono } from 'hono';

import type { RoutePath } from '@/../assets/build/route-paths';
import type { ConfigEnv } from '@/config';
import { setConfig } from '@/config';
import emptyMiddleware from '@/middleware/empty';

import type { Data, Namespace, Route } from './types';

export * from '@/types';
export { default as ofetch } from '@/utils/ofetch';
export * from '@/utils/parse-date';
export * from '@/utils';

let app: Hono | null = null;

Expand Down Expand Up @@ -70,6 +71,6 @@ export async function registerRoute(namespace: string, route: Route, namespaceCo
location: `custom/${namespace}`,
};

subApp.get(path, wrappedHandler);
subApp.get(path, route.param ? sValidator('param', route.param) : emptyMiddleware, route.query ? sValidator('query', route.query) : emptyMiddleware, wrappedHandler);
}
}
4 changes: 3 additions & 1 deletion lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import path from 'node:path';

import { serveStatic } from '@hono/node-server/serve-static';
import { sValidator } from '@hono/standard-validator';
import { directoryImport } from 'directory-import';
import type { Handler } from 'hono';
import { Hono } from 'hono';
import { routePath } from 'hono/route';

import { config } from '@/config';
import emptyMiddleware from '@/middleware/empty';
import healthz from '@/routes/healthz';
import index from '@/routes/index';
import metrics from '@/routes/metrics';
Expand Down Expand Up @@ -211,7 +213,7 @@ for (const namespace in namespaces) {
ctx.set('data', response);
}
};
subApp.get(path, wrappedHandler);
subApp.get(path, routeData.param ? sValidator('param', routeData.param) : emptyMiddleware, routeData.query ? sValidator('query', routeData.query) : emptyMiddleware, wrappedHandler);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bilibili/danmaku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function handler(ctx) {

let danmakuText = danmakuResponse.body;

danmakuText = await ((danmakuText[0] & 0x0f) === 0x08 ? zlib.inflateSync(danmakuText) : zlib.inflateRawSync(danmakuText));
danmakuText = await ((danmakuText[0] & 0x0F) === 0x08 ? zlib.inflateSync(danmakuText) : zlib.inflateRawSync(danmakuText));

let danmakuList = [];
const $ = load(danmakuText, { xmlMode: true });
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bilibili/wasm-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
};

const storeValue = (addr, v) => {
const nanHead = 0x7f_f8_00_00;
const nanHead = 0x7F_F8_00_00;

if (typeof v === 'number' && v !== 0) {
if (Number.isNaN(v)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/mercari/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function readDerLength(buf: Buffer, offset: number): { length: number; bytesRead
if (byte < 0x80) {
return { length: byte, bytesRead: 1 };
}
const bytesCount = byte & 0x7f;
const bytesCount = byte & 0x7F;
if (bytesCount > 4) {
throw new Error('DER length too long');
}
Expand Down
36 changes: 18 additions & 18 deletions lib/routes/telegram/channel-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ function ExpandInlineBytes(bytes: Buffer) {
throw new Error('cannot inflate a stripped jpeg');
}
const header = Buffer.from([
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x28, 0x1c, 0x1e, 0x23, 0x1e, 0x19, 0x28, 0x23, 0x21, 0x23, 0x2d, 0x2b,
0x28, 0x30, 0x3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0x04, 0x00, 0x00, 0x01, 0x7d, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1,
0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xc4, 0x00, 0x1f, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00,
0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62,
0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a,
0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2,
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9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x00, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xFF, 0xC4, 0x00, 0x1F, 0x00, 0x00, 0x01, 0x05,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xFF, 0xC4, 0x00, 0xB5, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04,
0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1,
0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A,
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0xC4, 0x00, 0x1F, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xFF, 0xC4, 0x00, 0xB5, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00,
0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62,
0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2,
0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3F, 0x00,
]);
const footer = Buffer.from([0xff, 0xd9]);
const footer = Buffer.from([0xFF, 0xD9]);
const real = Buffer.alloc(header.length + bytes.length + footer.length);
header.copy(real);
bytes.copy(real, header.length, 3);
Expand Down
30 changes: 15 additions & 15 deletions lib/routes/toutiao/a-bogus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function rotateLeft32(e, r) {

function T(j) {
if (0 <= j && j < 16) {
return 0x79_cc_45_19;
return 0x79_CC_45_19;
} else if (16 <= j && j < 64) {
return 0x7a_87_9d_8a;
return 0x7A_87_9D_8A;
} else {
logger.error('invalid j for constant Tj');
}
Expand Down Expand Up @@ -74,14 +74,14 @@ function GG(j, x, y, z) {
}

function reset(this: any) {
this.reg[0] = 0x73_80_16_6f;
this.reg[1] = 0x49_14_b2_b9;
this.reg[2] = 0x17_24_42_d7;
this.reg[3] = 0xda_8a_06_00;
this.reg[4] = 0xa9_6f_30_bc;
this.reg[5] = 0x16_31_38_aa;
this.reg[6] = 0xe3_8d_ee_4d;
this.reg[7] = 0xb0_fb_0e_4e;
this.reg[0] = 0x73_80_16_6F;
this.reg[1] = 0x49_14_B2_B9;
this.reg[2] = 0x17_24_42_D7;
this.reg[3] = 0xDA_8A_06_00;
this.reg[4] = 0xA9_6F_30_BC;
this.reg[5] = 0x16_31_38_AA;
this.reg[6] = 0xE3_8D_EE_4D;
this.reg[7] = 0xB0_FB_0E_4E;
this.chunk = [];
this.size = 0;
}
Expand Down Expand Up @@ -172,17 +172,17 @@ function _compress(this: any, t) {
const i = this.reg.slice(0);
for (let c = 0; c < 64; c++) {
let o = rotateLeft32(i[0], 12) + i[4] + rotateLeft32(T(c), c);
o = (0xff_ff_ff_ff & o) >>> 0;
o = (0xFF_FF_FF_FF & o) >>> 0;
o = rotateLeft32(o, 7);

const s = (o ^ rotateLeft32(i[0], 12)) >>> 0;
let u = FF(c, i[0], i[1], i[2]);
u = u + i[3] + s + f[c + 68];
u = (0xff_ff_ff_ff & u) >>> 0;
u = (0xFF_FF_FF_FF & u) >>> 0;

let b = GG(c, i[4], i[5], i[6]);
b = b + i[7] + o + f[c];
b = (0xff_ff_ff_ff & b) >>> 0;
b = (0xFF_FF_FF_FF & b) >>> 0;
i[3] = i[2];
i[2] = rotateLeft32(i[1], 9);
i[1] = i[0];
Expand All @@ -206,10 +206,10 @@ function _fill(this: any) {
}
for (let i = 0; i < 4; i++) {
const c = Math.floor(a / 0x1_00_00_00_00);
this.chunk.push((c >>> (8 * (3 - i))) & 0xff);
this.chunk.push((c >>> (8 * (3 - i))) & 0xFF);
}
for (let i = 0; i < 4; i++) {
this.chunk.push((a >>> (8 * (3 - i))) & 0xff);
this.chunk.push((a >>> (8 * (3 - i))) & 0xFF);
}
}

Expand Down
97 changes: 37 additions & 60 deletions lib/routes/v2ex/topics.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,44 @@
import type { Route } from '@/types';
import { ViewType } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { z } from 'zod';

export const route: Route = {
import { defineRoute, ViewType } from '@/types';
import { ofetch, parseDate } from '@/utils';

import type { Topic } from './types';

const topics = {
hot: '最热主题',
latest: '最新主题',
} as const;

export const route = defineRoute({
path: '/topics/:type',
param: z.object({
type: z.union((Object.keys(topics) as Array<keyof typeof topics>).map((key) => z.literal(key).describe(topics[key]))).describe('主题类型'),
}),
categories: ['bbs'],
view: ViewType.Articles,
example: '/v2ex/topics/latest',
parameters: {
type: {
description: '主题类型',
options: [
{
value: 'hot',
label: '最热主题',
},
{
value: 'latest',
label: '最新主题',
},
],
default: 'hot',
},
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '最热 / 最新主题',
maintainers: ['WhiteWorld'],
handler,
};
maintainers: ['WhiteWorld', 'hyoban'],
async handler(ctx) {
const { type } = ctx.req.valid('param');
const title = topics[type];
const data = (await ofetch(`https://www.v2ex.com/api/topics/${type}.json`)) as Array<Topic>;

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

const { data } = await got(`https://www.v2ex.com/api/topics/${type}.json`);

let title;
if (type === 'hot') {
title = '最热主题';
} else if (type === 'latest') {
title = '最新主题';
}

return {
title: `V2EX-${title}`,
link: 'https://www.v2ex.com/',
description: `V2EX-${title}`,
item: data.map((item) => ({
title: item.title,
description: `${item.member.username}: ${item.content_rendered}`,
content: { text: item.content, html: item.content_rendered },
pubDate: parseDate(item.created, 'X'),
link: item.url,
author: item.member.username,
comments: item.replies,
category: [item.node.title],
})),
};
}
return {
title: `V2EX-${title}`,
link: 'https://www.v2ex.com/',
description: `V2EX-${title}`,
item: data.map((item) => ({
title: item.title,
description: `${item.member.username}: ${item.content_rendered}`,
content: { text: item.content, html: item.content_rendered },
pubDate: parseDate(item.created, 'X'),
link: item.url,
author: item.member.username,
comments: item.replies,
category: [item.node.title],
})),
};
},
});
52 changes: 52 additions & 0 deletions lib/routes/v2ex/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export type Topic = {
node: {
avatar_large: string;
name: string;
avatar_normal: string;
title: string;
url: string;
topics: number;
footer: string;
header: string;
title_alternative: string;
avatar_mini: string;
stars: number;
aliases: Array<any>;
root: boolean;
id: number;
parent_node_name: string;
};
member: {
id: number;
username: string;
url: string;
website: string;
twitter?: string;
psn?: string;
github?: string;
btc?: string;
location: string;
tagline: string;
bio: string;
avatar_mini: string;
avatar_normal: string;
avatar_large: string;
created: number;
last_modified: number;
pro: number;
avatar_xlarge?: string;
avatar_xxlarge?: string;
avatar_xxxlarge?: string;
};
last_reply_by: string;
last_touched: number;
title: string;
url: string;
created: number;
deleted: number;
content: string;
content_rendered: string;
last_modified: number;
replies: number;
id: number;
};
2 changes: 1 addition & 1 deletion lib/routes/xiaoheihe/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function c3(v) {
}

function convertByte(v) {
return v & 0x80 ? 0xff & ((v << 1) ^ 0x1b) : v << 1;
return v & 0x80 ? 0xFF & ((v << 1) ^ 0x1B) : v << 1;
}

/**
Expand Down
Loading
Loading