This commit is contained in:
linyuchen
2024-04-15 00:09:08 +08:00
parent 0ef3e38d70
commit 356aba762c
218 changed files with 8465 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
import { Response } from 'express';
import { OB11Response } from '../action/OB11Response';
import { HttpServerBase } from '@/common/server/http';
import { actionHandlers } from '../action';
import { ob11Config } from '@/onebot11/config';
class OB11HTTPServer extends HttpServerBase {
name = 'OneBot V11 server';
handleFailed(res: Response, payload: any, e: any) {
res.send(OB11Response.error(e.stack.toString(), 200));
}
protected listen(port: number) {
if (ob11Config.enableHttp) {
super.listen(port);
}
}
}
export const ob11HTTPServer = new OB11HTTPServer();
setTimeout(() => {
for (const action of actionHandlers) {
for (const method of ['post', 'get']) {
ob11HTTPServer.registerRouter(method, action.actionName, (res, payload) => {
// @ts-expect-error wait fix
return action.handle(payload);
});
}
}
}, 0);