@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/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
  }