@joliegg/moderation 0.4.0 → 0.4.2

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.4.0",
3
+ "version": "0.4.2",
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
@@ -189,6 +189,16 @@ class ModerationClient {
189
189
  async moderateLink (url: string, allowShorteners = false): Promise<ModerationResult> {
190
190
  const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
191
191
 
192
+ if (blacklisted) {
193
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
194
+ }
195
+
196
+ const globallyBlacklisted = URLBlackList.some(b => url.indexOf(b) > -1);
197
+
198
+ if (globallyBlacklisted) {
199
+ return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
200
+ }
201
+
192
202
  if (!allowShorteners) {
193
203
  try {
194
204
  const domain = new URL(url).hostname;
@@ -197,25 +207,12 @@ class ModerationClient {
197
207
  if (isShortened) {
198
208
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
199
209
  }
200
- } catch (e) {
201
- const isShortened = URLShortenerList.some(s => url.indexOf(s) > -1);
202
-
203
- if (isShortened) {
204
- return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
205
- }
210
+ } catch (error) {
211
+ // Invalid URL
212
+ return { source: url, moderation: [] };
206
213
  }
207
214
  }
208
215
 
209
- if (blacklisted) {
210
- return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
211
- }
212
-
213
- const globallyBlacklisted = URLBlackList.some(b => url.indexOf(b) > -1);
214
-
215
- if (globallyBlacklisted) {
216
- return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
217
- }
218
-
219
216
  if (typeof this.googleAPIKey !== 'string') {
220
217
  return { source: url, moderation: [] };
221
218
  }