-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudyhack-demo.js
77 lines (54 loc) · 1.72 KB
/
cloudyhack-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @param context {WebtaskContext}
*/
var cloudinary = require("cloudinary");
function autoTagByID(context, cb){
var public_id = context.query.public_id || "flooded_road_1"; //existing asset if none passed
var options = { categorization: "google_tagging,imagga_tagging,aws_rek_tagging",
auto_tagging: 0.6, type:"upload" };
cloudinary.v2.uploader.explicit(public_id,options, function(error,result) {
if(error){
cb(error);
}
if(result){
console.log(result);
cb(null, result);
}
});
}
function test(context,cb){
var url = "https://res.cloudinary.com/demo-robert/image/upload/v1523390181/ec18d5b63b46a112b486a97a9d8885d7.jpg";
var options = {ocr: "adv_ocr"};
cloudinary.v2.uploader.upload(url,options, function(error,result) {
console.log(result);
var ocrResult = result.info.ocr.adv_ocr.data[0].fullTextAnnotation.text || 0;
console.log(ocrResult);
publicId = result.public_id;
if (ocrResult !== 0) {
cloudinary.v2.uploader.add_tag(ocrResult, publicId,
function(result) {
console.log(result)
});
}
});
}
function findByTag(context, cb){
var options ={context:true, tags:true, max_results:500};
cloudinary.v2.api.resources_by_tag("imageCon", options,
function(error, result){
if(error){
cb(error);
}
console.log(result);
cb(null, result);
});
}
module.exports = function(context, cb) {
cloudinary.config({
"cloud_name": context.secrets.cloud_name,
"api_key": context.secrets.api_key,
"api_secret": context.secrets.api_secret
});
//findByTag(context, cb);
autoTagByID(context,cb)
};