Skip to content

Commit

Permalink
修改插件接入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
yllhwa committed Oct 11, 2023
1 parent 674d7f8 commit aba4bde
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/html/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RSSWorker - Made with ❤</title>
</head>
<body>
<h1>RSSWorker - Made with ❤</h1>
<p>404 - Not Found</p>
<p>See <a href="https://github.com/yllhwa/RSSWorker">GitHub</a> for more information.</p>
</body>
</html>
14 changes: 14 additions & 0 deletions src/html/err.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RSSWorker - Made with ❤</title>
</head>
<body>
<h1>RSSWorker - Made with ❤</h1>
<p>500 - Internal Server Error</p>
<p>debug message: {ERROR_MESSAGE}</p>
<p>stack: <br />{ERROR_STACK}</p>
<p>See <a href="https://github.com/yllhwa/RSSWorker">GitHub</a> for more information.</p>
</body>
</html>
File renamed without changes.
6 changes: 5 additions & 1 deletion src/lib/bilibili/user/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ let deal = async (ctx) => {
return ctx.body(`${rss}`);
};

export { deal };
let setup = (route) => {
route.get('/bilibili/user/dynamic/:uid', deal);
};

export default { setup };
6 changes: 5 additions & 1 deletion src/lib/telegram/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ let deal = async (ctx) => {
return ctx.body(renderRss2(data));
};

export { deal };
let setup = (route) => {
route.get('/telegram/channel/:username', deal);
};

export default { setup };
6 changes: 5 additions & 1 deletion src/lib/weibo/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ let deal = async (ctx) => {
return ctx.body(renderRss2(finalData));
};

export { deal };
let setup = (route) => {
route.get('/weibo/user/:uid', deal);
};

export default { setup };
15 changes: 7 additions & 8 deletions src/route.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Hono } from 'hono';
import bilibili_user_dynamic from './lib/bilibili/user/dynamic';
import telegram_channel from './lib/telegram/channel';
import weibo_user from './lib/weibo/user';

const route = new Hono();

let getDealFunc = (module) => {
return module.deal;
};
let plugins = [bilibili_user_dynamic, telegram_channel, weibo_user];

route.get('/bilibili/user/dynamic/:uid', getDealFunc(await import('./lib/bilibili/user/dynamic')));
// route.get('/bilibili/test', getDealFunc(await import('./lib/bilibili/user/test_grpc')));
route.get('/telegram/channel/:username', getDealFunc(await import('./lib/telegram/channel')));
route.get('/weibo/user/:uid', getDealFunc(await import('./lib/weibo/user')));
route.get('/test/:username', getDealFunc(await import('./lib/tests/HTMLRewriterTest')));
for (let plugin of plugins) {
plugin.setup(route);
}

export default route;
14 changes: 13 additions & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Hono } from 'hono';
import { basicAuth } from 'hono/basic-auth';
import { cors } from 'hono/cors';
import indexHtml from './index.html';
import indexHtml from './html/index.html';
import notFoundHtml from './html/404.html';
import errorHtml from './html/err.html';
import robotsTxt from './robots.txt';

import route from './route';
Expand All @@ -18,6 +20,16 @@ app.get('robots.txt', (ctx) => {
app.get('/debug', (ctx) => {
return ctx.json(ctx.req.raw?.cf);
});
app.notFound((ctx) => {
return ctx.html(notFoundHtml);
});
app.onError((err, c) => {
let stack_str = err.stack;
let stack_arr = stack_str.split('\n').join('<br>');
let result = errorHtml.replace('{ERROR_MESSAGE}', `${err}`);
result = result.replace('{ERROR_STACK}', `${stack_arr}`);
return c.html(result, 500);
});
// app.use(
// '/*',
// basicAuth({
Expand Down

0 comments on commit aba4bde

Please sign in to comment.