Skip to content

Commit c4e2900

Browse files
author
agrandiere
committed
1.2.1
1 parent 0fdff4c commit c4e2900

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

README.MD

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,47 @@ sightengine.check(['nudity', 'type', 'properties','wad','face']).set_file('/full
6666

6767
## Moderate a binary image:
6868
```javascript
69-
// Detect nudity in an image
70-
sightengine.check(['nudity']).set_bytes(binary_image).then(function(result) {
69+
// Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type
70+
sightengine.check(['nudity', 'type', 'properties','wad','face']).set_bytes(binary_image).then(function(result) {
7171
// The result of the API
7272
}).catch(function(err) {
7373
// Error
7474
});
75+
```
7576

76-
// Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type
77-
sightengine.check(['nudity', 'type', 'properties','wad','face']).set_bytes(binary_image).then(function(result) {
77+
### Use fs.createReadStream
78+
```javascript
79+
var binaryImage = fs.createReadStream(path.resolve(__dirname, 'assets', 'image.jpg'));
80+
81+
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(binaryImage).then(function(result) {
7882
// The result of the API
7983
}).catch(function(err) {
8084
// Error
8185
});
8286
```
8387

88+
### Use a base64 string
89+
```javascript
90+
// var i64 = image64string;
91+
92+
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(i64, 'image.png').then(function(result) {
93+
// The result of the API
94+
}).catch(function(err) {
95+
// Error
96+
});
97+
```
98+
99+
### Use a base64 string from a file
100+
```javascript
101+
var i64 = new Buffer(fs.readFileSync(path.resolve(__dirname, 'assets', 'image.jpg'))).toString('base64');
102+
103+
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(i64, 'image.png').then(function(result) {
104+
// The result of the API
105+
}).catch(function(err) {
106+
// Error
107+
});
108+
```
109+
84110
# Video and Stream Moderation
85111
The first step to detect nudity in a video stream is to submit the video stream to the API.
86112

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sightengine",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "",
55
"main": "sightengine.js",
66
"scripts": {

sightengine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ function makeClient(api_user, api_secret) {
4343
});
4444
};
4545

46-
client.set_bytes = (binaryImage) => {
46+
client.set_bytes = (binaryImage, filename) => {
4747
const form = new FormData();
4848
var url = endpoint + '1.0/check.json';
4949

5050
form.append('api_user', apiUser);
5151
form.append('api_secret', apiSecret);
5252
form.append('models', _models.join());
53-
form.append('media', binaryImage);
53+
form.append('media', binaryImage, { filename : filename });
5454

5555
return fetch(url, { method: 'POST', body: form, headers: { 'user-agent': 'SE-SDK-NODEJS' + version}}).then(function(res) {
5656
return res.json();

tests.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,22 @@ describe('test image moderation', function() {
5555

5656
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(binaryImage).then(function(result) {
5757
done(assert.equal('success', result.status))
58-
})
58+
});
59+
});
60+
61+
it('should return success', function(done) {
62+
var i64 = new Buffer(fs.readFileSync(path.resolve(__dirname, 'assets', 'image.jpg'))).toString('base64');
63+
64+
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(i64, 'image.png').then(function(result) {
65+
done(assert.equal('success', result.status))
66+
});
67+
68+
/* Use a base64 string
69+
var i64 = 'base64string';
70+
71+
sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities']).set_bytes(i64, 'image.png').then(function(result) {
72+
done(assert.equal('success', result.status))
73+
}); */
5974
});
6075

6176
it('should return error', function(done) {
@@ -72,7 +87,6 @@ describe('video moderation', () => {
7287
.check(['nudity', 'wad', 'properties', 'type', 'face', 'celebrities'])
7388
.video('https://sightengine.com/assets/stream/examples/funfair.mp4', 'http://requestb.in/1d097l71')
7489
.then(result => {
75-
console.log(result);
7690
assert.equal('success', result.status)
7791
})
7892
})

0 commit comments

Comments
 (0)