mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
optimize: an ActiveHttpAdapter does not need to register actions
This commit is contained in:
parent
a9ca951854
commit
5a5257294b
@ -7,14 +7,15 @@ import { QuickAction, QuickActionEvent } from '../types';
|
|||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { NapCatOneBot11Adapter } from '../main';
|
import { NapCatOneBot11Adapter } from '../main';
|
||||||
import { handleQuickOperation } from '../helper/quick';
|
import { handleQuickOperation } from '../helper/quick';
|
||||||
|
|
||||||
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
url: string;
|
url: string;
|
||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
|
||||||
heartbeatInterval: number;
|
heartbeatInterval: number;
|
||||||
secret: string | undefined;
|
secret: string | undefined;
|
||||||
coreContext: NapCatCore;
|
coreContext: NapCatCore;
|
||||||
onebotContext: NapCatOneBot11Adapter;
|
onebotContext: NapCatOneBot11Adapter;
|
||||||
logger: LogWrapper;
|
logger: LogWrapper;
|
||||||
|
|
||||||
constructor(url: string, heartbeatInterval: number, secret: string | undefined, coreContext: NapCatCore, onebotContext: NapCatOneBot11Adapter) {
|
constructor(url: string, heartbeatInterval: number, secret: string | undefined, coreContext: NapCatCore, onebotContext: NapCatOneBot11Adapter) {
|
||||||
this.heartbeatInterval = heartbeatInterval;
|
this.heartbeatInterval = heartbeatInterval;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
@ -23,12 +24,13 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
this.onebotContext = onebotContext;
|
this.onebotContext = onebotContext;
|
||||||
this.logger = coreContext.context.logger;
|
this.logger = coreContext.context.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerHeartBeat() {
|
registerHeartBeat() {
|
||||||
// HttpPost 心跳
|
// HttpPost 心跳
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||||
this.actionMap.set(action.actionName, action);
|
// Passive http adapter does not need to register actions
|
||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||||
@ -38,13 +40,11 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
};
|
};
|
||||||
const msgStr = JSON.stringify(event);
|
const msgStr = JSON.stringify(event);
|
||||||
if (this.secret && this.secret.length > 0) {
|
if (this.secret && this.secret.length > 0) {
|
||||||
|
|
||||||
const hmac = createHmac('sha1', this.secret);
|
const hmac = createHmac('sha1', this.secret);
|
||||||
hmac.update(msgStr);
|
hmac.update(msgStr);
|
||||||
const sig = hmac.digest('hex');
|
const sig = hmac.digest('hex');
|
||||||
headers['x-signature'] = 'sha1=' + sig;
|
headers['x-signature'] = 'sha1=' + sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(this.url, {
|
fetch(this.url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
@ -63,8 +63,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.logger.logError('新消息事件HTTP上报返回快速操作失败', e);
|
this.logger.logError('新消息事件HTTP上报返回快速操作失败', e);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async open() {
|
async open() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user