Skip to content

Commit 6ecb7ce

Browse files
committed
Implement image collection methods in VR4 node
1 parent 2918c88 commit 6ecb7ce

2 files changed

Lines changed: 110 additions & 16 deletions

File tree

services/visual_recognition/v4-collection-utils.html

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
<option value="deleteAllCollections">Delete all collections</option>
4646
<option disabled>______________</option>
4747
<option value="addImages">Add image to collection</option>
48+
<option value="listImages">List images in a collection</option>
49+
<option value="getImageDetails">Get details of image in collection</option>
50+
<option value="deleteImage">Delete image from collection</option>
51+
<option value="getJpegImage">Get JPEG image from collection</option>
4852
</select>
4953
</div>
5054
</script>
@@ -111,13 +115,25 @@
111115
your needs.</p>
112116
<p>The following features are available :</p>
113117
<ul>
114-
<li><b>Create a collection</b></li>
115-
<li><b>List listCollections</b></li>
116-
<li><b>Get collection details</b></li>
117-
<li><b>Update collection</b></li>
118-
<li><b>Delete collection</b></li>
119-
<li><b>Delete all collections</b></li>
120-
<li><b>Add images to collection</b></li>
118+
<li>Collections
119+
<ul>
120+
<li><b>Create a collection</b></li>
121+
<li><b>List listCollections</b></li>
122+
<li><b>Get collection details</b></li>
123+
<li><b>Update collection</b></li>
124+
<li><b>Delete collection</b></li>
125+
<li><b>Delete all collections</b></li>
126+
</ul>
127+
</li>
128+
<li>Images
129+
<ul>
130+
<li><b>Add images to collection</b></li>
131+
<li><b>List images in collection</b></li>
132+
<li><b>Get details of image in collection</b></li>
133+
<li><b>Delete image from collection</b></li>
134+
<li><b>Get JPEG image from collection</b></li>
135+
</ul>
136+
</li>
121137
</ul>
122138

123139
<p>All Results will made available at <code>msg.payload</code></p>
@@ -180,6 +196,46 @@
180196
<p>More information on this
181197
<a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v4?code=node#add-images">
182198
API documentation</a>.</p>
183-
199+
200+
<p><b>List images in collection</b></p>
201+
<p>this feature should be provided in input : </p>
202+
<ul>
203+
<li><code>msg.params["collectionId"]</code> : The identifier of the collection (Required)</li>
204+
</ul>
205+
<p>More information on this
206+
<a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v4?code=node#list-images">
207+
API documentation</a>.</p>
208+
209+
<p><b>Get details of image in collection</b></p>
210+
<p>this feature should be provided in input : </p>
211+
<ul>
212+
<li><code>msg.params["collectionId"]</code> : The identifier of the collection (Required)</li>
213+
<li><code>msg.params["imageId"]</code> : The identifier of the image (Required)</li>
214+
</ul>
215+
<p>More information on this
216+
<a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v4?code=node#get-image-details">
217+
API documentation</a>.</p>
218+
219+
<p><b>Delete image from collection</b></p>
220+
<p>this feature should be provided in input : </p>
221+
<ul>
222+
<li><code>msg.params["collectionId"]</code> : The identifier of the collection (Required)</li>
223+
<li><code>msg.params["imageId"]</code> : The identifier of the image (Required)</li>
224+
</ul>
225+
<p>More information on this
226+
<a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v4?code=node#delete-an-image">
227+
API documentation</a>.</p>
228+
229+
<p><b>Get JPEG image from collection</b></p>
230+
<p>this feature should be provided in input : </p>
231+
<ul>
232+
<li><code>msg.params["collectionId"]</code> : The identifier of the collection (Required)</li>
233+
<li><code>msg.params["imageId"]</code> : The identifier of the image (Required)</li>
234+
<li><code>msg.params["size"]</code> : Set to either 'full' or 'thumbnail' (Optional)</li>
235+
</ul>
236+
<p>More information on this
237+
<a href="https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v4?code=node#delete-an-image">
238+
API documentation</a>.</p>
239+
184240

185241
</script>

services/visual_recognition/v4-collection-utils.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ module.exports = function(RED) {
2424
'getCollection': ['collectionId'],
2525
'updateCollection': ['collectionId'],
2626
'deleteCollection': ['collectionId'],
27-
'addImages': ['collectionId']
27+
'addImages': ['collectionId'],
28+
'listImages': ['collectionId'],
29+
'getImageDetails': ['collectionId', 'imageId'],
30+
'deleteImage': ['collectionId', 'imageId'],
31+
'getJpegImage': ['collectionId', 'imageId']
2832
};
2933

3034
var pkg = require('../../package.json'),
@@ -76,15 +80,41 @@ module.exports = function(RED) {
7680
});
7781
}
7882

79-
function processTheResponse (body, node, msg) {
80-
if (body == null) {
81-
return Promise.reject('call to watson visual recognition v4 service failed');
82-
} else if (node.config[FEATURE] === 'deleteCollection') {
83+
function responseForDeleteMode(node, msg) {
84+
let feature = node.config[FEATURE];
85+
let field = null;
86+
87+
switch (feature) {
88+
case 'deleteCollection':
8389
msg.payload = 'Successfully deleted collection id: ' + msg.params.collectionId;
84-
} else {
85-
msg.payload = body;
90+
break;
91+
case 'deleteImage':
92+
msg.payload = 'Successfully deleted image id: '
93+
+ msg.params.imageId
94+
+ ' from collection '
95+
+ msg.params.collectionId;
96+
break
97+
default:
98+
return false;
8699
}
87-
return Promise.resolve();
100+
return true;
101+
}
102+
103+
function processTheResponse (body, node, msg) {
104+
return new Promise(function resolver(resolve, reject) {
105+
if (body == null) {
106+
return reject('call to watson visual recognition v4 service failed');
107+
} else if (! responseForDeleteMode(node, msg)) {
108+
msg.payload = body;
109+
payloadutils.checkForStream(msg)
110+
.then(() => {
111+
resolve();
112+
})
113+
.catch((err) => {
114+
reject(err);
115+
})
116+
}
117+
});
88118
}
89119

90120
function extractIDs(body) {
@@ -243,6 +273,10 @@ module.exports = function(RED) {
243273
case 'updateCollection':
244274
case 'deleteCollection':
245275
case 'addImages':
276+
case 'listImages':
277+
case 'getImageDetails':
278+
case 'deleteImage':
279+
case 'getJpegImage':
246280
theMissing = paramCheckFor(REQUIRED_PARAMS[feature], msg);
247281
if (theMissing.length === 0) {
248282
return Promise.resolve();
@@ -336,6 +370,10 @@ module.exports = function(RED) {
336370
case 'updateCollection':
337371
case 'deleteCollection':
338372
case 'deleteAllCollections':
373+
case 'listImages':
374+
case 'getImageDetails':
375+
case 'deleteImage':
376+
case 'getJpegImage':
339377
return Promise.resolve();
340378
case 'addImages':
341379
if (!msg.payload) {

0 commit comments

Comments
 (0)