@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.
- package/dist/index.js +16 -16
- package/package.json +1 -1
- 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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const isShortened = url_shorteners_json_1.default.some(
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
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
|
-
|
|
190
|
+
try {
|
|
191
|
+
const domain = new URL(url).hostname;
|
|
191
192
|
|
|
192
|
-
|
|
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
|
-
|
|
195
|
+
if (blacklisted) {
|
|
196
|
+
return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
|
|
197
|
+
}
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
return { source: url, moderation: [{ category: 'BLACK_LIST', confidence: 100 }] };
|
|
200
|
-
}
|
|
199
|
+
const globallyBlacklisted = URLBlackList.some(u => u === domain);
|
|
201
200
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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') {
|