@joliegg/moderation 0.3.5 → 0.3.7

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/dist/index.js CHANGED
@@ -129,9 +129,18 @@ class ModerationClient {
129
129
  async moderateLink(url, allowShorteners = false) {
130
130
  const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
131
131
  if (!allowShorteners) {
132
- const isShortened = url_shorteners_json_1.default.some(s => url.indexOf(s) > -1);
133
- if (isShortened) {
134
- return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
132
+ try {
133
+ const domain = new URL(url).hostname;
134
+ const isShortened = url_shorteners_json_1.default.some(s => s.indexOf(domain) > -1);
135
+ if (isShortened) {
136
+ return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
137
+ }
138
+ }
139
+ catch (e) {
140
+ const isShortened = url_shorteners_json_1.default.some(s => url.indexOf(s) > -1);
141
+ if (isShortened) {
142
+ return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
143
+ }
135
144
  }
136
145
  }
137
146
  if (blacklisted) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
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
@@ -159,10 +159,19 @@ class ModerationClient {
159
159
  const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
160
160
 
161
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 }] };
162
+ try {
163
+ const domain = new URL(url).hostname;
164
+ const isShortened = URLShortenerList.some(s => s.indexOf(domain) > -1);
165
+
166
+ if (isShortened) {
167
+ return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
168
+ }
169
+ } catch (e) {
170
+ const isShortened = URLShortenerList.some(s => url.indexOf(s) > -1);
171
+
172
+ if (isShortened) {
173
+ return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
174
+ }
166
175
  }
167
176
  }
168
177
 
@@ -176,7 +185,6 @@ class ModerationClient {
176
185
  return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
177
186
  }
178
187
 
179
-
180
188
  if (typeof this.googleAPIKey !== 'string') {
181
189
  return { source: url, moderation: [] };
182
190
  }