增加白名单过滤
This commit is contained in:
parent
68fe869945
commit
33152abf71
@ -2,9 +2,12 @@
|
|||||||
* 通知逻辑
|
* 通知逻辑
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EChangeType, INotifyInfo, IRecordInfo } from './interface';
|
import { EChangeType, INotifyConfig, INotifyInfo, IRecordInfo } from './interface';
|
||||||
|
import { __ROOT__ } from '../../config/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotifyService {
|
export class NotifyService {
|
||||||
@ -30,6 +33,8 @@ export class NotifyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async notifyItemChange(data: INotifyInfo[], channel: string, itemId: number | string, type: EChangeType) {
|
async notifyItemChange(data: INotifyInfo[], channel: string, itemId: number | string, type: EChangeType) {
|
||||||
|
const whites = this.readWhiteUids();
|
||||||
|
data = data.filter(d => !whites[channel].includes(d.uid));
|
||||||
if (data.length === 0) return;
|
if (data.length === 0) return;
|
||||||
|
|
||||||
const key = `${channel}-${type}`;
|
const key = `${channel}-${type}`;
|
||||||
@ -46,6 +51,12 @@ export class NotifyService {
|
|||||||
// this.records.set(key, old);
|
// this.records.set(key, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readWhiteUids() {
|
||||||
|
const file = path.resolve(__ROOT__, 'temp/whiteUids.txt');
|
||||||
|
const str = fs.readFileSync(file).toString();
|
||||||
|
return JSON.parse(str) as Record<string, string[]>;
|
||||||
|
}
|
||||||
|
|
||||||
private formatItem(channel: string, data: INotifyInfo[], itemId: string | number, type: EChangeType) {
|
private formatItem(channel: string, data: INotifyInfo[], itemId: string | number, type: EChangeType) {
|
||||||
return this._itemTemplate
|
return this._itemTemplate
|
||||||
.replace('channel', channel)
|
.replace('channel', channel)
|
||||||
|
1
temp/whiteUids.txt
Normal file
1
temp/whiteUids.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"硬核":[],"官包":[]}
|
Loading…
Reference in New Issue
Block a user