mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-12 16:00:27 +00:00
NapCatQQ
This commit is contained in:
32
src/onebot11/server/http.ts
Normal file
32
src/onebot11/server/http.ts
Normal 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);
|
||||
Reference in New Issue
Block a user