From efa9b1fbabfa706d91f118f8253edab52e25f116 Mon Sep 17 00:00:00 2001 From: Lex <6548146+qpn6ph9q@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:40:05 +1200 Subject: [PATCH] Add text moderation portion of the API --- sightengine.js | 13 +++++++++++++ tests.js | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) mode change 100644 => 100755 sightengine.js mode change 100644 => 100755 tests.js diff --git a/sightengine.js b/sightengine.js old mode 100644 new mode 100755 index 33977d2..b060bdd --- a/sightengine.js +++ b/sightengine.js @@ -83,6 +83,19 @@ function makeClient(api_user, api_secret) { }); }; + client.text = (text, lang, opt_countries, callback) => { + const url = endpoint + '/1.0/text/check.json'; + const mode = _models?.[0] || 'standard'; + const data = { text, lang, opt_countries, mode, 'callback_url': callback, 'api_user': apiUser, 'api_secret': apiSecret }; + const querystring = encodeQueryData(data); + + return fetch(url + '?' + querystring, { headers: { 'user-agent': 'SE-SDK-NODEJS' + version } }).then((res) => { + return res.json(); + }).catch((error) => { + return error; + }); + }; + client.feedback = (model, modelClass, image) => { var url = endpoint + '1.0/feedback.json' diff --git a/tests.js b/tests.js old mode 100644 new mode 100755 index 6ba8134..3f878a9 --- a/tests.js +++ b/tests.js @@ -103,5 +103,15 @@ describe('video sync moderation', () => { }) }) - - +describe('text moderation', () => { + it('should return success', () => { + return sightengine + .check(['standard']) + .text('You are such a slut') + .then(result => { + assert.equal('success', result.status) + assert.equal('discriminatory', result?.profanity?.matches?.type) + assert.equal('slut', result?.profanity?.matches?.match) + }) + }) +})