@joliegg/moderation 0.3.4 → 0.3.5
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/README.md +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -1
- package/dist/url-shorteners.json +1548 -0
- package/package.json +1 -1
- package/src/index.ts +10 -1
- package/src/url-shorteners.json +1548 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { SpeechClient, protos } from '@google-cloud/speech';
|
|
|
7
7
|
import sharp from 'sharp';
|
|
8
8
|
|
|
9
9
|
import URLBlackList from './url-blacklist.json';
|
|
10
|
+
import URLShortenerList from './url-shorteners.json';
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
import { ModerationCategory, ModerationConfiguration, ModerationResult, ThreatsResponse } from './types';
|
|
@@ -154,9 +155,17 @@ class ModerationClient {
|
|
|
154
155
|
return { source: url, moderation: [] };
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
async moderateLink (url: string): Promise<ModerationResult> {
|
|
158
|
+
async moderateLink (url: string, allowShorteners = false): Promise<ModerationResult> {
|
|
158
159
|
const blacklisted = this.urlBlackList?.some(b => url.indexOf(b) > -1);
|
|
159
160
|
|
|
161
|
+
if (!allowShorteners) {
|
|
162
|
+
const isShortened = URLShortenerList.some(s => url.indexOf(s) > -1);
|
|
163
|
+
|
|
164
|
+
if (isShortened) {
|
|
165
|
+
return { source: url, moderation: [{ category: 'URL_SHORTENER', confidence: 100 }] };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
160
169
|
if (blacklisted) {
|
|
161
170
|
return { source: url, moderation: [{ category: 'CUSTOM_BLACK_LIST', confidence: 100 }] };
|
|
162
171
|
}
|