mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
save
This commit is contained in:
@@ -38,11 +38,15 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
|||||||
if (args?.[1] instanceof Array) {
|
if (args?.[1] instanceof Array) {
|
||||||
for (let receiveData of args?.[1]) {
|
for (let receiveData of args?.[1]) {
|
||||||
const ntQQApiMethodName = receiveData.cmdName;
|
const ntQQApiMethodName = receiveData.cmdName;
|
||||||
log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||||
for (let hook of receiveHooks) {
|
for (let hook of receiveHooks) {
|
||||||
if (hook.method === ntQQApiMethodName) {
|
if (hook.method === ntQQApiMethodName) {
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
hook.hookFunc(receiveData.payload);
|
try {
|
||||||
|
hook.hookFunc(receiveData.payload);
|
||||||
|
}catch (e) {
|
||||||
|
log("hook error", e, receiveData.payload)
|
||||||
|
}
|
||||||
}).then()
|
}).then()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {getConfigUtil, log} from "../common/utils";
|
import {getConfigUtil, log} from "../common/utils";
|
||||||
|
|
||||||
// const express = require("express");
|
// const express = require("express");
|
||||||
import express from "express";
|
import express = require("express");
|
||||||
import {Request} from 'express';
|
import {Request} from 'express';
|
||||||
import {Response} from 'express';
|
import {Response} from 'express';
|
||||||
|
|
||||||
@@ -180,14 +180,18 @@ export function startExpress(port: number) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function registerRouter<PayloadType, ReturnDataType>(action: OB11ApiName, handle: (payload: PayloadType) => Promise<OB11Return<ReturnDataType>>) {
|
async function registerRouter<PayloadType, ReturnDataType>(action: OB11ApiName, handle: (payload: PayloadType) => Promise<OB11Return<ReturnDataType>>) {
|
||||||
|
let url = action.toString()
|
||||||
|
if (!action.startsWith("/")){
|
||||||
|
url = "/" + action
|
||||||
|
}
|
||||||
async function _handle(res: Response, payload: PayloadType) {
|
async function _handle(res: Response, payload: PayloadType) {
|
||||||
res.send(await handle(payload))
|
res.send(await handle(payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
app.post('/' + action, (req: Request, res: Response) => {
|
app.post(url, (req: Request, res: Response) => {
|
||||||
_handle(res, req.body).then()
|
_handle(res, req.body).then()
|
||||||
});
|
});
|
||||||
app.get('/' + action, (req: Request, res: Response) => {
|
app.get(url, (req: Request, res: Response) => {
|
||||||
_handle(res, req.query as any).then()
|
_handle(res, req.query as any).then()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user