File tree Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ let Inputs = require('./Inputs');
55let Concepts = require ( './Concepts' ) ;
66let Workflow = require ( './Workflow' ) ;
77let Workflows = require ( './Workflows' ) ;
8+ let Solutions = require ( './solutions/Solutions' ) ;
89let { API , ERRORS , getBasePath} = require ( './constants' ) ;
910let { TOKEN_PATH } = API ;
1011
@@ -106,6 +107,7 @@ class App {
106107 this . concepts = new Concepts ( this . _config ) ;
107108 this . workflow = new Workflow ( this . _config ) ;
108109 this . workflows = new Workflows ( this . _config ) ;
110+ this . solutions = new Solutions ( this . _config ) ;
109111 }
110112
111113 _getToken ( resolve , reject ) {
@@ -136,6 +138,5 @@ class App {
136138 } ) ;
137139 }
138140}
139- ;
140141
141142module . exports = App ;
Original file line number Diff line number Diff line change 1+ let axios = require ( 'axios' ) ;
2+ let { wrapToken} = require ( '../utils' ) ;
3+ let { isSuccess, clone} = require ( '../helpers' ) ;
4+
5+ let BASE_URL = 'https://api.clarifai-moderation.com' ;
6+
7+ class Moderation {
8+
9+ constructor ( _config ) {
10+ this . _config = _config ;
11+
12+ }
13+
14+ predict ( modelID , imageURL ) {
15+ return wrapToken ( this . _config , ( headers ) => {
16+ let url = `${ BASE_URL } /v2/models/${ modelID } /outputs` ;
17+ let params = {
18+ inputs : [
19+ {
20+ data : {
21+ image : {
22+ url : imageURL
23+ }
24+ }
25+ }
26+ ]
27+ } ;
28+
29+ return new Promise ( ( resolve , reject ) => {
30+ return axios . post ( url , params , { headers} ) . then ( ( response ) => {
31+ if ( isSuccess ( response ) ) {
32+ let data = clone ( response . data ) ;
33+ resolve ( data ) ;
34+ } else {
35+ reject ( response ) ;
36+ }
37+ } , reject ) ;
38+ } ) ;
39+ } ) ;
40+ }
41+
42+ getModerationStatus ( imageID ) {
43+ return wrapToken ( this . _config , ( headers ) => {
44+ let url = `${ BASE_URL } /v2/inputs/${ imageID } /outputs` ;
45+ return new Promise ( ( resolve , reject ) => {
46+ return axios . get ( url , { headers} ) . then ( ( response ) => {
47+ let data = clone ( response . data ) ;
48+ resolve ( data ) ;
49+ } , reject ) ;
50+
51+ } ) ;
52+ } ) ;
53+ }
54+ }
55+
56+ module . exports = Moderation ;
Original file line number Diff line number Diff line change 1+ let Moderation = require ( './Moderation' ) ;
2+
3+ class Solutions {
4+
5+ constructor ( _config ) {
6+ this . moderation = new Moderation ( _config ) ;
7+ }
8+ }
9+
10+ module . exports = Solutions ;
You can’t perform that action at this time.
0 commit comments