qf46578 commited on
Commit
bdf4e76
·
verified ·
1 Parent(s): 57d80b0

Lobster Evolution v2.8.0 | TS: 20260227-0302 | Gene: Stable

Browse files
server/server/src/services/sensitivityService.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PrismaClient } from '@prisma/client';
2
+
3
+ export class SensitivityService {
4
+ private prisma = new PrismaClient();
5
+
6
+ // 1. 过滤敏感词
7
+ public async filter(text: string): Promise<{ cleanText: string; intercepted: boolean; blocks: string[] }> {
8
+ const words = await this.prisma.sensitiveWord.findMany();
9
+ let cleanText = text;
10
+ let intercepted = false;
11
+ const blocks: string[] = [];
12
+
13
+ for (const item of words) {
14
+ if (text.includes(item.word)) {
15
+ blocks.push(item.word);
16
+ if (item.level === 2) intercepted = true;
17
+ cleanText = cleanText.replace(new RegExp(item.word, 'g'), '***');
18
+ }
19
+ }
20
+
21
+ return { cleanText, intercepted, blocks };
22
+ }
23
+ }