@joliegg/moderation 0.4.2 → 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 +16 -16
  2. package/package.json +1 -1
  3. package/src/index.ts +16 -15
package/dist/index.js CHANGED
@@ -151,26 +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 (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
- }
162
- if (!allowShorteners) {
163
- try {
164
- const domain = new URL(url).hostname;
165
- const isShortened = url_shorteners_json_1.default.some(s => s.indexOf(domain) > -1);
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 }] };
159
+ }
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);
166
166
  if (isShortened) {
167
167
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
168
168
  }
169
169
  }
170
- catch (error) {
171
- // Invalid URL
172
- return { source: url, moderation: [] };
173
- }
170
+ }
171
+ catch (error) {
172
+ // Invalid URL
173
+ return { source: url, moderation: [] };
174
174
  }
175
175
  if (typeof this.googleAPIKey !== 'string') {
176
176
  return { source: url, moderation: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.4.2",
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,30 +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 (blacklisted) {
193
- return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
194
- }
193
+ const blacklisted = this.urlBlackList?.some(u => u.indexOf(url) > -1);
195
194
 
196
- const globallyBlacklisted = URLBlackList.some(b => url.indexOf(b) > -1);
195
+ if (blacklisted) {
196
+ return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
197
+ }
197
198
 
198
- if (globallyBlacklisted) {
199
- return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
200
- }
199
+ const globallyBlacklisted = URLBlackList.some(u => u === domain);
201
200
 
202
- if (!allowShorteners) {
203
- try {
204
- const domain = new URL(url).hostname;
205
- const isShortened = URLShortenerList.some(s => s.indexOf(domain) > -1);
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);
206
207
 
207
208
  if (isShortened) {
208
209
  return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
209
210
  }
210
- } catch (error) {
211
- // Invalid URL
212
- return { source: url, moderation: [] };
213
211
  }
212
+ } catch (error) {
213
+ // Invalid URL
214
+ return { source: url, moderation: [] };
214
215
  }
215
216
 
216
217
  if (typeof this.googleAPIKey !== 'string') {