@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 +10 -12
- package/dist/url-blacklist.json +38865 -5174
- package/package.json +1 -1
- package/src/index.ts +13 -16
- package/src/url-blacklist.json +38865 -5174
package/package.json
CHANGED
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 (
|
|
201
|
-
|
|
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
|
}
|