增加白名单过滤

This commit is contained in:
colter 2024-01-02 20:51:08 +08:00
parent 68fe869945
commit 33152abf71
2 changed files with 13 additions and 1 deletions

View File

@ -2,9 +2,12 @@
*
*/
import fs from 'fs';
import path from 'path';
import axios from 'axios';
import { Injectable } from '@nestjs/common';
import { EChangeType, INotifyInfo, IRecordInfo } from './interface';
import { EChangeType, INotifyConfig, INotifyInfo, IRecordInfo } from './interface';
import { __ROOT__ } from '../../config/config';
@Injectable()
export class NotifyService {
@ -30,6 +33,8 @@ export class NotifyService {
}
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;
const key = `${channel}-${type}`;
@ -46,6 +51,12 @@ export class NotifyService {
// 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) {
return this._itemTemplate
.replace('channel', channel)

1
temp/whiteUids.txt Normal file
View File

@ -0,0 +1 @@
{"硬核":[],"官包":[]}