Skip to content

Commit 62753c4

Browse files
committed
Support multiple eager transformations with explicit api
1 parent 442d0e2 commit 62753c4

File tree

4 files changed

+24
-39
lines changed

4 files changed

+24
-39
lines changed

lib/utils.js

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

lib/utils.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/utils.coffee

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ exports.archive_params = (options = {})->
828828
tags: options.tags && exports.build_array(options.tags)
829829
public_ids: options.public_ids && exports.build_array(options.public_ids)
830830
prefixes: options.prefixes && exports.build_array(options.prefixes)
831-
transformations: build_eager(options.transformations)
831+
transformations: utils.build_eager(options.transformations)
832832

833833
build_custom_headers = (headers)->
834834
(for a in Array(headers) when a?.join?
@@ -839,7 +839,7 @@ exports.build_explicit_api_params = (public_id, options = {})->
839839
opt = [
840840
callback: options.callback
841841
custom_coordinates: options.custom_coordinates && utils.encode_double_array(options.custom_coordinates)
842-
eager: build_eager(options.eager)
842+
eager: utils.build_eager(options.eager)
843843
eager_async: utils.as_safe_bool(options.eager_async)
844844
eager_notification_url: options.eager_notification_url
845845
face_coordinates: options.face_coordinates && utils.encode_double_array(options.face_coordinates)
@@ -884,16 +884,6 @@ exports.only = (hash, keys...) ->
884884
###*
885885
# @private
886886
###
887-
build_eager = (eager)->
888-
return undefined unless eager?
889-
ret = (for transformation in Array(eager)
890-
transformation = _.clone(transformation)
891-
format = transformation.format if transformation.format?
892-
delete transformation.format
893-
_.compact([utils.generate_transformation_string(transformation), format]).join("/")
894-
).join("|")
895-
ret
896-
897887

898888
hashToQuery = (hash)->
899889
_.compact(for key, value of hash

test/utils_spec.coffee

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ describe "utils", ->
381381
expect(utils.build_upload_params(options)['transformation']).to.eql("c_scale,w_100")
382382
expect(Object.keys(options).length).to.eql(2)
383383

384+
it "build_explicit_api_params should support mutiple eager transformations with a pipe" , ->
385+
options = {
386+
eager: [
387+
{width:100, crop:"scale"},
388+
{height:100, crop:"fit"},
389+
]
390+
}
391+
expect(utils.build_explicit_api_params('some_id', options)[0]['eager']).to.eql("c_scale,w_100|c_fit,h_100")
392+
393+
it "archive_params should support mutiple eager transformations with a pipe" , ->
394+
options = {
395+
transformations: [
396+
{width:200, crop:"scale"},
397+
{height:200, crop:"fit"},
398+
]
399+
}
400+
expect(utils.archive_params(options)['transformations']).to.eql("c_scale,w_200|c_fit,h_200")
401+
384402
it "build_upload_params canonize booleans" , ->
385403
options = {backup:true, use_filename:false, colors:"true", exif:"false", colors:"true", image_metadata:"false", invalidate:1, eager_async:"1"}
386404
params = utils.build_upload_params(options)

0 commit comments

Comments
 (0)