部分推送不加密

This commit is contained in:
luying
2022-06-16 20:21:02 +08:00
parent f4fe5e1aef
commit e4720f2a9f

View File

@@ -85,14 +85,14 @@ export async function sendMessageToUsersWithSuc(route: string, data: any, uids:
// 推送给个人的方法收束于这个函数
export async function sendMessageToUsers(route: string, data: any, uids: { uid: string, sid: string }[]) {
if(uids.length > 0) {
pinus.app.get('channelService').pushMessageByUids(route, encryptMsg(data), uids);
pinus.app.get('channelService').pushMessageByUids(route, encryptMsg(route, data), uids);
infologger.debug(`pushMessage route: ${route} data: ${JSON.stringify(data)} members: ${uids.map(obj => obj.uid).join()}`);
}
}
export async function sendMessageToTeam(teamCode: string, route: string, data: any) {
const channel = pinus.app.get('channelService').getChannel(teamCode);
sendMessageToChannel(channel, route, resResult(STATUS.SUCCESS, encryptMsg(data)));
sendMessageToChannel(channel, route, resResult(STATUS.SUCCESS, encryptMsg(route, data)));
}
/**
@@ -171,10 +171,19 @@ function getKvFromMemory() {
return { k, v }
}
function encryptMsg(json: any) {
function encryptMsg(event: string, json: any) {
if(checkNotEncryptRoute(event)) return json
let kv = getKvFromMemory();
let msgEncrypt = new MsgEncrypt(kv);
let { aesKey, aesIV } = msgEncrypt.getEncodeKv();
let data = msgEncrypt.encryptMsg(json);
return { data, k: aesKey, v: aesIV }
}
function checkNotEncryptRoute(event: string) {
return [
PUSH_ROUTE.PUSH_CURRENT_TIME,
PUSH_ROUTE.RACE_START,
PUSH_ROUTE.GUILD_ACTIVITY_END,
].indexOf(event) != -1
}