基本实现完成GM API
This commit is contained in:
@ -6,9 +6,9 @@ export async function sendMessage(msg: MessageSend, action: string, data?: any):
|
||||
LoggerCore.getInstance().logger().trace("sendMessage", { action, data, response: res });
|
||||
if (res && res.code) {
|
||||
console.error(res);
|
||||
return Promise.reject(res.message);
|
||||
throw res.message;
|
||||
} else {
|
||||
return Promise.resolve(res.data);
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,20 +138,7 @@ export function forwardMessage(
|
||||
to: MessageSend,
|
||||
middleware?: ApiFunctionSync
|
||||
) {
|
||||
from.on(path, (params, fromCon) => {
|
||||
if (middleware) {
|
||||
// 此处是为了处理CustomEventMessage的同步消息情况
|
||||
const resp = middleware(params, fromCon) as any;
|
||||
if (resp instanceof Promise) {
|
||||
return resp.then((data) => {
|
||||
if (data !== false) {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
} else if (resp !== false) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
const handler = (params: any, fromCon: GetSender) => {
|
||||
const fromConnect = fromCon.getConnect();
|
||||
if (fromConnect) {
|
||||
connect(to, prefix + "/" + path, params).then((toCon) => {
|
||||
@ -171,5 +158,22 @@ export function forwardMessage(
|
||||
} else {
|
||||
return sendMessage(to, prefix + "/" + path, params);
|
||||
}
|
||||
};
|
||||
from.on(path, (params, sender) => {
|
||||
if (middleware) {
|
||||
// 此处是为了处理CustomEventMessage的同步消息情况
|
||||
const resp = middleware(params, sender) as any;
|
||||
if (resp instanceof Promise) {
|
||||
return resp.then((data) => {
|
||||
if (data !== false) {
|
||||
return data;
|
||||
}
|
||||
return handler(params, sender);
|
||||
});
|
||||
} else if (resp !== false) {
|
||||
return resp;
|
||||
}
|
||||
return handler(params, sender);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user