@joliegg/moderation 0.4.1 → 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/package.json +1 -1
- package/src/index.ts +13 -16
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 (
|
|
164
|
-
|
|
165
|
-
|
|
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
|
}
|
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
|
}
|