filestack / filestack-rails

Official Ruby on Rails plugin for Filestack File Picker that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
https://www.filestack.com
Apache License 2.0
223 stars 101 forks source link

Fixed the initialization of filestack client v3 #247

Closed yoones closed 3 months ago

yoones commented 6 months ago

filestack-js v3's init function expects two arguments: the api key and an object representing the eventual options (cname, ...). For instance:

const clientOptions = {
  security: {
    policy: "eyJleHBpcnkiOiAxNTQ2ODk5NDI4LCAiY2FsbCI6IFsicmVhZCIsICJzdGF0IiwgImNvbnZlcnQiLCAicGljayIsICJzdG9yZSJdfQ==",
    signature: "1fed86599156df046f925e0f773866654a4fc209b0b85b173b5d8088e898b685"
  },
  cname: 'fs.mydomain.com'
}

const client = filestack.init(YOUR_API_KEY, clientOptions)

The current filestack_js_init_tag helper can initialize a filestack client but the cname is not properly passed because the current code generates this:

var #{client_name} = filestack.init('#{apikey}', #{signature_and_policy}, '#{cname}');

The cname is passed as a third argument instead of being part of object passed as second argument. This used to work (at least with filestack-js v1) but in v3, it does not.

This patch uses the right init arguments when it runs with filestack-js v3.