@joliegg/moderation 0.4.1 → 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.
Files changed (3) hide show
  1. package/dist/index.js +10 -12
  2. package/package.json +1 -1
  3. package/src/index.ts +13 -16
package/dist/index.js CHANGED
@@ -152,6 +152,13 @@ class ModerationClient {
152
152
  }
153
153
  async moderateLink(url, allowShorteners = false) {
154
154
  const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
155
+ if (blacklisted) {
156
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
157
+ }
158
+ const globallyBlacklisted = url_blacklist_json_1.default.some(b => url.indexOf(b) > -1);
159
+ if (globallyBlacklisted) {
160
+ return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
161
+ }
155
162
  if (!allowShorteners) {
156
163
  try {
157
164
  const domain = new URL(url).hostname;
@@ -160,20 +167,11 @@ class ModerationClient {
160
167
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
161
168
  }
162
169
  }
163
- catch (e) {
164
- const isShortened = url_shorteners_json_1.default.some(s => url.indexOf(s) > -1);
165
- if (isShortened) {
166
- return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
167
- }
170
+ catch (error) {
171
+ // Invalid URL
172
+ return { source: url, moderation: [] };
168
173
  }
169
174
  }
170
- if (blacklisted) {
171
- return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
172
- }
173
- const globallyBlacklisted = url_blacklist_json_1.default.some(b => url.indexOf(b) > -1);
174
- if (globallyBlacklisted) {
175
- return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
176
- }
177
175
  if (typeof this.googleAPIKey !== 'string') {
178
176
  return { source: url, moderation: [] };
179
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.4.1",
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
  }