@joliegg/moderation 0.4.1 → 0.4.3

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 +14 -16
  2. package/package.json +1 -1
  3. package/src/index.ts +18 -20
package/dist/index.js CHANGED
@@ -151,28 +151,26 @@ class ModerationClient {
151
151
  return { source: url, moderation: [] };
152
152
  }
153
153
  async moderateLink(url, allowShorteners = false) {
154
- const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
155
- if (!allowShorteners) {
156
- try {
157
- const domain = new URL(url).hostname;
158
- const isShortened = url_shorteners_json_1.default.some(s => s.indexOf(domain) > -1);
159
- if (isShortened) {
160
- return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
161
- }
154
+ try {
155
+ const domain = new URL(url).hostname;
156
+ const blacklisted = this.urlBlackList?.some(u => u.indexOf(url) > -1);
157
+ if (blacklisted) {
158
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
162
159
  }
163
- catch (e) {
164
- const isShortened = url_shorteners_json_1.default.some(s => url.indexOf(s) > -1);
160
+ const globallyBlacklisted = url_blacklist_json_1.default.some(u => u === domain);
161
+ if (globallyBlacklisted) {
162
+ return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
163
+ }
164
+ if (!allowShorteners) {
165
+ const isShortened = url_shorteners_json_1.default.some(u => u === domain);
165
166
  if (isShortened) {
166
167
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
167
168
  }
168
169
  }
169
170
  }
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 }] };
171
+ catch (error) {
172
+ // Invalid URL
173
+ return { source: url, moderation: [] };
176
174
  }
177
175
  if (typeof this.googleAPIKey !== 'string') {
178
176
  return { source: url, moderation: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
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
@@ -187,33 +187,31 @@ class ModerationClient {
187
187
  }
188
188
 
189
189
  async moderateLink (url: string, allowShorteners = false): Promise<ModerationResult> {
190
- const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
190
+ try {
191
+ const domain = new URL(url).hostname;
191
192
 
192
- if (!allowShorteners) {
193
- try {
194
- const domain = new URL(url).hostname;
195
- const isShortened = URLShortenerList.some(s => s.indexOf(domain) > -1);
193
+ const blacklisted = this.urlBlackList?.some(u => u.indexOf(url) > -1);
196
194
 
197
- if (isShortened) {
198
- return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
199
- }
200
- } catch (e) {
201
- const isShortened = URLShortenerList.some(s => url.indexOf(s) > -1);
195
+ if (blacklisted) {
196
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
197
+ }
198
+
199
+ const globallyBlacklisted = URLBlackList.some(u => u === domain);
200
+
201
+ if (globallyBlacklisted) {
202
+ return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
203
+ }
204
+
205
+ if (!allowShorteners) {
206
+ const isShortened = URLShortenerList.some(u => u === domain);
202
207
 
203
208
  if (isShortened) {
204
209
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
205
210
  }
206
211
  }
207
- }
208
-
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 }] };
212
+ } catch (error) {
213
+ // Invalid URL
214
+ return { source: url, moderation: [] };
217
215
  }
218
216
 
219
217
  if (typeof this.googleAPIKey !== 'string') {