Skip to content

Commit

Permalink
Merge pull request #118 from cloudinary/explicit-eager-transformations
Browse files Browse the repository at this point in the history
Support multiple eager transformations with explicit api
  • Loading branch information
tocker authored Oct 31, 2016
2 parents 442d0e2 + 62753c4 commit 4e328a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 deletions.
29 changes: 3 additions & 26 deletions lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/utils.js.map

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions src/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ exports.archive_params = (options = {})->
tags: options.tags && exports.build_array(options.tags)
public_ids: options.public_ids && exports.build_array(options.public_ids)
prefixes: options.prefixes && exports.build_array(options.prefixes)
transformations: build_eager(options.transformations)
transformations: utils.build_eager(options.transformations)

build_custom_headers = (headers)->
(for a in Array(headers) when a?.join?
Expand All @@ -839,7 +839,7 @@ exports.build_explicit_api_params = (public_id, options = {})->
opt = [
callback: options.callback
custom_coordinates: options.custom_coordinates && utils.encode_double_array(options.custom_coordinates)
eager: build_eager(options.eager)
eager: utils.build_eager(options.eager)
eager_async: utils.as_safe_bool(options.eager_async)
eager_notification_url: options.eager_notification_url
face_coordinates: options.face_coordinates && utils.encode_double_array(options.face_coordinates)
Expand Down Expand Up @@ -884,16 +884,6 @@ exports.only = (hash, keys...) ->
###*
# @private
###
build_eager = (eager)->
return undefined unless eager?
ret = (for transformation in Array(eager)
transformation = _.clone(transformation)
format = transformation.format if transformation.format?
delete transformation.format
_.compact([utils.generate_transformation_string(transformation), format]).join("/")
).join("|")
ret


hashToQuery = (hash)->
_.compact(for key, value of hash
Expand Down
18 changes: 18 additions & 0 deletions test/utils_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,24 @@ describe "utils", ->
expect(utils.build_upload_params(options)['transformation']).to.eql("c_scale,w_100")
expect(Object.keys(options).length).to.eql(2)

it "build_explicit_api_params should support mutiple eager transformations with a pipe" , ->
options = {
eager: [
{width:100, crop:"scale"},
{height:100, crop:"fit"},
]
}
expect(utils.build_explicit_api_params('some_id', options)[0]['eager']).to.eql("c_scale,w_100|c_fit,h_100")

it "archive_params should support mutiple eager transformations with a pipe" , ->
options = {
transformations: [
{width:200, crop:"scale"},
{height:200, crop:"fit"},
]
}
expect(utils.archive_params(options)['transformations']).to.eql("c_scale,w_200|c_fit,h_200")

it "build_upload_params canonize booleans" , ->
options = {backup:true, use_filename:false, colors:"true", exif:"false", colors:"true", image_metadata:"false", invalidate:1, eager_async:"1"}
params = utils.build_upload_params(options)
Expand Down

0 comments on commit 4e328a9

Please sign in to comment.