@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.
- package/dist/index.js +14 -16
- package/package.json +1 -1
- 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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
171
|
-
|
|
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
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
|
-
|
|
190
|
+
try {
|
|
191
|
+
const domain = new URL(url).hostname;
|
|
191
192
|
|
|
192
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
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') {
|