Skip to content

Commit b15bac6

Browse files
author
Amir Tocker
committed
Merge branch 'feature/search-by-context'
2 parents fefa663 + 0074344 commit b15bac6

File tree

10 files changed

+69
-19
lines changed

10 files changed

+69
-19
lines changed

lib/api.js

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/uploader.js

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/uploader.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v2/api.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v2/api.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
_ = require("lodash")
2-
if process.env.CLOUDINARY_TEST_UNSECURE == 'http'
2+
config = require("./config")
3+
if config().upload_prefix && config().upload_prefix[0..4] == 'http:'
34
https = require('http')
45
else
56
https = require('https')
67
utils = require("./utils")
7-
config = require("./config")
88
querystring = require("querystring")
99
Q = require('q')
1010

@@ -104,6 +104,14 @@ exports.resources_by_tag = (tag, callback, options = {}) ->
104104
uri = ["resources", resource_type, "tags", tag]
105105
call_api("get", uri, api.only(options, "next_cursor", "max_results", "tags", "context", "direction", "moderations"), callback, options)
106106

107+
exports.resources_by_context= (key,value, callback, options = {}) ->
108+
resource_type = options["resource_type"] ? "image"
109+
uri = ["resources", resource_type, "context"]
110+
params = api.only(options, "next_cursor", "max_results", "tags", "context", "direction", "moderations")
111+
params.key = key
112+
params.value = value if value?
113+
call_api("get", uri,params , callback, options)
114+
107115
exports.resources_by_moderation = (kind, status, callback, options = {}) ->
108116
resource_type = options["resource_type"] ? "image"
109117
uri = ["resources", resource_type, "moderations", kind, status]

src/uploader.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
_ = require("lodash")
2-
https = require('https')
2+
config = require("./config")
3+
if config().upload_prefix && config().upload_prefix[0..4] == 'http:'
4+
https = require('http')
5+
else
6+
https = require('https')
37
#http = require('http')
48
UploadStream = require('./upload_stream')
59
utils = require("./utils")
610
util = require("util")
7-
config = require("./config")
811
fs = require('fs')
912
path = require('path')
1013
Q = require('q')
@@ -361,4 +364,4 @@ exports.image_upload_tag = (field, options = {}) ->
361364
return '<input ' + utils.html_attrs(tag_options) + '/>'
362365

363366
exports.unsigned_image_upload_tag = (field, upload_preset, options = {}) ->
364-
exports.image_upload_tag(field, utils.merge(options, unsigned: true, upload_preset: upload_preset))
367+
exports.image_upload_tag(field, utils.merge(options, unsigned: true, upload_preset: upload_preset))

src/v2/api.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ utils.v1_adapters exports, api,
77
resource_types: 0,
88
resources: 0,
99
resources_by_tag: 1,
10+
resources_by_context: 2,
1011
resources_by_moderation: 2,
1112
resources_by_ids: 1
1213
resource: 1,
@@ -42,4 +43,4 @@ utils.v1_adapters exports, api,
4243
create_streaming_profile: 1,
4344
publish_by_ids: 1,
4445
publish_by_tag: 1,
45-
publish_by_prefix: 1
46+
publish_by_prefix: 1

test/api_spec.coffee

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ describe "api", ->
8787
PUBLIC_ID_2 = PUBLIC_ID_PREFIX + "_2_" + SUFFIX
8888
PUBLIC_ID_3 = PUBLIC_ID_PREFIX + "_3_" + SUFFIX
8989
PUBLIC_ID_4 = PUBLIC_ID_PREFIX + "_4_" + SUFFIX
90+
PUBLIC_ID_5 = PUBLIC_ID_PREFIX + "_5_" + SUFFIX
91+
PUBLIC_ID_6 = PUBLIC_ID_PREFIX + "_6_" + SUFFIX
9092

9193
NAMED_TRANSFORMATION = "api_test_transformation" + SUFFIX
9294
API_TEST_UPLOAD_PRESET1 = "api_test_upload_preset_1_" + SUFFIX
@@ -114,17 +116,19 @@ describe "api", ->
114116
callback(result)
115117

116118
before (done) ->
117-
@timeout 0
119+
@timeout helper.TIMEOUT_LONG
118120
@timestamp_tag = "#{TEST_TAG}_#{cloudinary.utils.timestamp()}"
119121

120-
Q.all [
122+
Q.allSettled [
121123
cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID, tags: [TEST_TAG, @timestamp_tag], context: "key=value", eager: [EXPLICIT_TRANSFORMATION])
122-
cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID_2, tags: [TEST_TAG, @timestamp_tag], context: "key=value", eager: [EXPLICIT_TRANSFORMATION])]
124+
cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID_2, tags: [TEST_TAG, @timestamp_tag], context: "key=value", eager: [EXPLICIT_TRANSFORMATION])
125+
cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID_5, tags: [TEST_TAG, @timestamp_tag], context: "test-key=test", eager: [EXPLICIT_TRANSFORMATION])
126+
cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID_6, tags: [TEST_TAG, @timestamp_tag], context: "test-key=alt-test", eager: [EXPLICIT_TRANSFORMATION])]
123127
.finally ->
124128
done()
125129

126130
after (done) ->
127-
@timeout 0
131+
@timeout helper.TIMEOUT_LONG
128132
@timestamp_tag = "#{TEST_TAG}_#{cloudinary.utils.timestamp()}"
129133

130134
Q.all [
@@ -190,6 +194,20 @@ describe "api", ->
190194
done()
191195

192196

197+
it "should allow listing resources by context only", (done) ->
198+
@timeout helper.TIMEOUT_MEDIUM
199+
cloudinary.v2.api.resources_by_context "test-key",null, (error, result) ->
200+
return done(new Error error.message) if error?
201+
expect(result.resources).to.have.length(2)
202+
done()
203+
204+
it "should allow listing resources by context key and value", (done) ->
205+
@timeout helper.TIMEOUT_MEDIUM
206+
cloudinary.v2.api.resources_by_context "test-key","test", (error, result) ->
207+
return done(new Error error.message) if error?
208+
expect(result.resources).to.have.length(1)
209+
done()
210+
193211
it "should allow listing resources by public ids", (done) ->
194212
@timeout helper.TIMEOUT_MEDIUM
195213
cloudinary.v2.api.resources_by_ids [PUBLIC_ID, PUBLIC_ID_2], context: true, tags: true, (error, result) ->

0 commit comments

Comments
 (0)