@joliegg/moderation 0.3.4 → 0.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
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
@@ -7,6 +7,7 @@ import { SpeechClient, protos } from '@google-cloud/speech';
7
7
  import sharp from 'sharp';
8
8
 
9
9
  import URLBlackList from './url-blacklist.json';
10
+ import URLShortenerList from './url-shorteners.json';
10
11
 
11
12
 
12
13
  import { ModerationCategory, ModerationConfiguration, ModerationResult, ThreatsResponse } from './types';
@@ -154,9 +155,17 @@ class ModerationClient {
154
155
  return { source: url, moderation: [] };
155
156
  }
156
157
 
157
- async moderateLink (url: string): Promise<ModerationResult> {
158
+ async moderateLink (url: string, allowShorteners = false): Promise<ModerationResult> {
158
159
  const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
159
160
 
161
+ if (!allowShorteners) {
162
+ const isShortened = URLShortenerList.some(s => url.indexOf(s) > -1);
163
+
164
+ if (isShortened) {
165
+ return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
166
+ }
167
+ }
168
+
160
169
  if (blacklisted) {
161
170
  return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
162
171
  }