@joliegg/moderation 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,6 +32,7 @@ const client = new ModerationClient({
32
32
  apiKey: GOOGLE_API_KEY
33
33
  },
34
34
  banlist: ['some word'],
35
+ urlBlackList: ['someurl.example'],
35
36
  });
36
37
  ```
37
38
 
@@ -54,7 +55,7 @@ Currently only OGG files are supported
54
55
 
55
56
  ```js
56
57
 
57
- const audioModeration = await client.moderateAudio('https://example.example/image.ogg');
58
+ const audioModeration = await client.moderateAudio('https://example.example/image.ogg', 'en-US');
58
59
  ```
59
60
 
60
61
  ### Moderating Links
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ModerationConfiguration, ModerationResult } from './types';
2
2
  /**
3
3
  * Moderation Client
4
4
  *
5
- * @name ModerationClient
5
+ * @class ModerationClient
6
6
  */
7
7
  declare class ModerationClient {
8
8
  private rekognitionClient?;
@@ -10,6 +10,7 @@ declare class ModerationClient {
10
10
  private googleSpeechClient?;
11
11
  private googleAPIKey?;
12
12
  private banList?;
13
+ private urlBlackList?;
13
14
  /**
14
15
  *
15
16
  * @param {ModerationConfiguration} configuration
@@ -35,6 +36,6 @@ declare class ModerationClient {
35
36
  */
36
37
  moderateImage(url: string, minimumConfidence?: number): Promise<ModerationResult>;
37
38
  moderateLink(url: string): Promise<ModerationResult>;
38
- moderateAudio(url: string, minimumConfidence?: number): Promise<ModerationResult>;
39
+ moderateAudio(url: string, language?: string, minimumConfidence?: number): Promise<ModerationResult>;
39
40
  }
40
41
  export default ModerationClient;
package/dist/index.js CHANGED
@@ -12,14 +12,15 @@ const url_blacklist_json_1 = __importDefault(require("./url-blacklist.json"));
12
12
  /**
13
13
  * Moderation Client
14
14
  *
15
- * @name ModerationClient
15
+ * @class ModerationClient
16
16
  */
17
17
  class ModerationClient {
18
18
  rekognitionClient;
19
19
  googleLanguageClient;
20
20
  googleSpeechClient;
21
21
  googleAPIKey;
22
- banList;
22
+ banList = [];
23
+ urlBlackList = [];
23
24
  /**
24
25
  *
25
26
  * @param {ModerationConfiguration} configuration
@@ -38,6 +39,9 @@ class ModerationClient {
38
39
  if (Array.isArray(configuration.banList)) {
39
40
  this.banList = configuration.banList;
40
41
  }
42
+ if (Array.isArray(configuration.urlBlackList)) {
43
+ this.urlBlackList = configuration.urlBlackList;
44
+ }
41
45
  }
42
46
  /**
43
47
  * Returns a list of moderation categories detected on a text
@@ -54,7 +58,7 @@ class ModerationClient {
54
58
  const matches = this.banList.filter(w => normalizedText.indexOf(w) > -1);
55
59
  if (matches.length > 0) {
56
60
  categories.push({
57
- category: 'Ban List',
61
+ category: 'BAN_LIST',
58
62
  confidence: matches.length,
59
63
  });
60
64
  }
@@ -121,8 +125,12 @@ class ModerationClient {
121
125
  return { source: url, moderation: [] };
122
126
  }
123
127
  async moderateLink(url) {
124
- const blacklisted = url_blacklist_json_1.default.some(b => url.indexOf(b) > -1);
128
+ const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
125
129
  if (blacklisted) {
130
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
131
+ }
132
+ const globallyBlacklisted = url_blacklist_json_1.default.some(b => url.indexOf(b) > -1);
133
+ if (globallyBlacklisted) {
126
134
  return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
127
135
  }
128
136
  if (typeof this.googleAPIKey !== 'string') {
@@ -147,7 +155,7 @@ class ModerationClient {
147
155
  }
148
156
  return { source: url, moderation: [] };
149
157
  }
150
- async moderateAudio(url, minimumConfidence = 50) {
158
+ async moderateAudio(url, language = 'en-US', minimumConfidence = 50) {
151
159
  if (typeof this.googleSpeechClient === 'undefined') {
152
160
  return { source: url, moderation: [] };
153
161
  }
@@ -155,7 +163,7 @@ class ModerationClient {
155
163
  const options = {
156
164
  encoding: 'OGG_OPUS',
157
165
  sampleRateHertz: 48000,
158
- languageCode: 'es-US'
166
+ languageCode: language,
159
167
  };
160
168
  const [response] = await this.googleSpeechClient.recognize({
161
169
  audio: { content: Buffer.from(data, 'binary').toString('base64') },
@@ -6,6 +6,7 @@ export interface ModerationConfiguration {
6
6
  keyFile?: string;
7
7
  };
8
8
  banList?: string[];
9
+ urlBlackList?: string[];
9
10
  }
10
11
  export interface ModerationCategory {
11
12
  category: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A set of tools for chat moderation",
5
5
  "author": "Diana Islas Ocampo",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -19,7 +19,7 @@ type ISpeechRecognitionResult = protos.google.cloud.speech.v1.ISpeechRecognition
19
19
  /**
20
20
  * Moderation Client
21
21
  *
22
- * @name ModerationClient
22
+ * @class ModerationClient
23
23
  */
24
24
  class ModerationClient {
25
25
 
@@ -27,7 +27,8 @@ class ModerationClient {
27
27
  private googleLanguageClient?: LanguageServiceClient;
28
28
  private googleSpeechClient?: SpeechClient;
29
29
  private googleAPIKey?: string;
30
- private banList?: string[];
30
+ private banList?: string[] = [];
31
+ private urlBlackList?: string[] = [];
31
32
 
32
33
  /**
33
34
  *
@@ -50,6 +51,10 @@ class ModerationClient {
50
51
  if (Array.isArray(configuration.banList)) {
51
52
  this.banList = configuration.banList;
52
53
  }
54
+
55
+ if (Array.isArray(configuration.urlBlackList)) {
56
+ this.urlBlackList = configuration.urlBlackList;
57
+ }
53
58
  }
54
59
 
55
60
  /**
@@ -69,7 +74,7 @@ class ModerationClient {
69
74
 
70
75
  if (matches.length > 0) {
71
76
  categories.push({
72
- category: 'Ban List',
77
+ category: 'BAN_LIST',
73
78
  confidence: matches.length,
74
79
  });
75
80
  }
@@ -148,9 +153,15 @@ class ModerationClient {
148
153
  }
149
154
 
150
155
  async moderateLink (url: string): Promise<ModerationResult> {
151
- const blacklisted = URLBlackList.some(b => url.indexOf(b) > -1);
156
+ const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
152
157
 
153
158
  if (blacklisted) {
159
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
160
+ }
161
+
162
+ const globallyBlacklisted = URLBlackList.some(b => url.indexOf(b) > -1);
163
+
164
+ if (globallyBlacklisted) {
154
165
  return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
155
166
  }
156
167
 
@@ -185,7 +196,7 @@ class ModerationClient {
185
196
  return { source: url, moderation: [] };
186
197
  }
187
198
 
188
- async moderateAudio (url: string, minimumConfidence: number = 50): Promise<ModerationResult> {
199
+ async moderateAudio (url: string, language: string = 'en-US', minimumConfidence: number = 50): Promise<ModerationResult> {
189
200
  if (typeof this.googleSpeechClient === 'undefined') {
190
201
  return { source: url, moderation: [] };
191
202
  }
@@ -196,7 +207,7 @@ class ModerationClient {
196
207
  const options: IRecognitionConfig = {
197
208
  encoding: 'OGG_OPUS',
198
209
  sampleRateHertz: 48000,
199
- languageCode: 'es-US'
210
+ languageCode: language,
200
211
  };
201
212
 
202
213
  const [ response ] = await this.googleSpeechClient.recognize ({
@@ -7,6 +7,7 @@ export interface ModerationConfiguration {
7
7
  keyFile?: string;
8
8
  };
9
9
  banList?: string[];
10
+ urlBlackList?: string[];
10
11
  }
11
12
 
12
13
  export interface ModerationCategory {