filestack-rails 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +113 -110
- data/Rakefile +2 -11
- data/app/helpers/filestack_rails/application_helper.rb +78 -0
- data/app/helpers/filestack_rails/form_helper.rb +32 -0
- data/lib/filestack-rails.rb +7 -0
- data/lib/filestack_rails/configuration.rb +25 -0
- data/lib/filestack_rails/engine.rb +17 -0
- data/lib/filestack_rails/transform.rb +46 -0
- data/lib/filestack_rails/version.rb +3 -0
- data/lib/tasks/filestack_rails_tasks.rake +4 -0
- metadata +27 -69
- data/MIT-LICENSE +0 -20
- data/app/helpers/filepicker_rails/application_helper.rb +0 -276
- data/app/helpers/filepicker_rails/form_helper.rb +0 -72
- data/lib/filepicker-rails.rb +0 -7
- data/lib/filepicker_rails/configuration.rb +0 -77
- data/lib/filepicker_rails/engine.rb +0 -17
- data/lib/filepicker_rails/policy.rb +0 -46
- data/lib/filepicker_rails/tag.rb +0 -44
- data/lib/filepicker_rails/version.rb +0 -3
@@ -1,72 +0,0 @@
|
|
1
|
-
module FilepickerRails
|
2
|
-
module FormHelper
|
3
|
-
|
4
|
-
include FilepickerRails::Tag
|
5
|
-
|
6
|
-
# Creates a filepicker field, accepts optional `options` hash for configuration.
|
7
|
-
#
|
8
|
-
# #### Options
|
9
|
-
#
|
10
|
-
# - `:button_text` - The text of the upload button.
|
11
|
-
# - `:button_class` - The class of the upload button.
|
12
|
-
# - `:extensions` - The extensions of file types you want to support for this upload. Ex: `.png,.jpg`.
|
13
|
-
# - `:mimetypes` - The file types you want to support for this upload. Ex: `image/png,text/*`.
|
14
|
-
# - `:container` - Where to show the file picker dialog can be `modal`, `window` or the id of an iframe on the page.
|
15
|
-
# - `:multiple` - (true or false) Whether or not multiple uploads can be saved at once.
|
16
|
-
# - `:services` - What services your users can upload to. Ex: `BOX, COMPUTER, FACEBOOK`.
|
17
|
-
# - `:store_path` - The path to store the file at within the specified file store.
|
18
|
-
# - `:store_location` - The file is not copied by default. It remains in the original location. If you wish you have the file copied onto your own storage, you can specify where we should put the copy. The only value at the moment is `S3`.
|
19
|
-
# - `:store_container` - The bucket or container in your specified `store_location`. Defaults to the container specified in the developer portal. Does not apply to Dropbox storage.
|
20
|
-
# - `:store_access` - Should the underlying file be publicly available on its S3 link. Options are `public` and `private`, defaults to 'private'.
|
21
|
-
# - `:dragdrop` - (`true` or `false`) Whether or not to allow drag-and-drop uploads.
|
22
|
-
# - `:drag_text` - The text of the dragdrop pane.
|
23
|
-
# - `:drag_class` - The class of the dragdrop pane.
|
24
|
-
# - `:onchange` - The onchange event.
|
25
|
-
# - `:max_size` - The maximum file size allowed, in bytes.
|
26
|
-
# - `:max_files` - The maximum number of files.
|
27
|
-
# - `:open_to` - Open the picker to the given service. Ex: `COMPUTER`.
|
28
|
-
# - `:class` - Add a class to the input.
|
29
|
-
# - `:value` - Define the value of the input
|
30
|
-
# - `:language` - Open the picker to the given language. Ex: `fr`.
|
31
|
-
#
|
32
|
-
# #### Examples
|
33
|
-
#
|
34
|
-
# filepicker_field(:filepicker_url)
|
35
|
-
# # => <input data-fp-apikey="..." id="user_filepicker_url" name="user[filepicker_url]" type="filepicker" />
|
36
|
-
#
|
37
|
-
# This is mixed on form for to be used like.
|
38
|
-
#
|
39
|
-
# <%= form_for @user do |f| %>
|
40
|
-
# <%= f.filepicker_field :filepicker_url %>
|
41
|
-
# <%= f.submit %>
|
42
|
-
# <% end %>
|
43
|
-
#
|
44
|
-
def filepicker_field(method, options = {})
|
45
|
-
define_input_options(options)
|
46
|
-
@method = method
|
47
|
-
if rails_greater_than_4?
|
48
|
-
rails_greater_than_4_input
|
49
|
-
else
|
50
|
-
rails_input
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
attr_reader :method, :object_name, :template
|
57
|
-
|
58
|
-
def rails_greater_than_4_input
|
59
|
-
tag = ActionView::Helpers::Tags::TextField.new(object_name, method, template, objectify_options(input_options))
|
60
|
-
tag.send(:add_default_name_and_id, input_options)
|
61
|
-
tag.render
|
62
|
-
end
|
63
|
-
|
64
|
-
def rails_input
|
65
|
-
ActionView::Helpers::InstanceTag.new(object_name, method, template).to_input_field_tag(type, input_options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def rails_greater_than_4?
|
69
|
-
::Rails.version.to_i >= 4
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/filepicker-rails.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module FilepickerRails
|
2
|
-
class Configuration
|
3
|
-
|
4
|
-
# Define your API Key to be used.
|
5
|
-
#
|
6
|
-
# #### Examples
|
7
|
-
#
|
8
|
-
# This is to be used on the `config/application.rb`:
|
9
|
-
#
|
10
|
-
# config.filepicker_rails.api_key = 'Your filepicker.io API Key'
|
11
|
-
#
|
12
|
-
attr_writer :api_key
|
13
|
-
|
14
|
-
# Define your Secret key to be used on Policy.
|
15
|
-
#
|
16
|
-
# More info about Policy on [Ink documentation](https://developers.filepicker.io/docs/security/)
|
17
|
-
#
|
18
|
-
# #### Examples
|
19
|
-
#
|
20
|
-
# This is to be used on the `config/application.rb`:
|
21
|
-
#
|
22
|
-
# config.filepicker_rails.secret_key = 'Your filepicker.io Secret Key'
|
23
|
-
#
|
24
|
-
attr_writer :secret_key
|
25
|
-
|
26
|
-
# @private
|
27
|
-
attr_reader :secret_key
|
28
|
-
|
29
|
-
# Set your CDN Path to be used
|
30
|
-
#
|
31
|
-
# More info about CDN on [Ink documentation](https://developers.filepicker.io/docs/cdn/)
|
32
|
-
#
|
33
|
-
# #### Examples
|
34
|
-
#
|
35
|
-
# This is to be used on the `config/application.rb`:
|
36
|
-
#
|
37
|
-
# config.filepicker_rails.cdn_host = 'Your CDN host name'
|
38
|
-
#
|
39
|
-
attr_writer :cdn_host
|
40
|
-
|
41
|
-
# @private
|
42
|
-
attr_reader :cdn_host
|
43
|
-
|
44
|
-
# @private
|
45
|
-
def api_key
|
46
|
-
@api_key or raise "Set config.filepicker_rails.api_key"
|
47
|
-
end
|
48
|
-
|
49
|
-
# Define the expire time when using Policy.
|
50
|
-
#
|
51
|
-
# By default the expiry time is 10 minutes.
|
52
|
-
# If you need to change the expiry time this should be an integer and
|
53
|
-
# it is expressed in seconds since the [Epoch](http://en.wikipedia.org/wiki/Unix_time).
|
54
|
-
#
|
55
|
-
# #### Examples
|
56
|
-
#
|
57
|
-
# This is to be used on the `config/application.rb`:
|
58
|
-
#
|
59
|
-
# config.filepicker_rails.expiry = -> { (Time.zone.now + 5.minutes).to_i }
|
60
|
-
# # Define the expiry time to 5 minutes
|
61
|
-
#
|
62
|
-
# If you need always the same url, a static expiry time, to do some cache.
|
63
|
-
# You can set a date starting of the Epoch.
|
64
|
-
#
|
65
|
-
# config.filepicker_rails.expiry = -> { 100.years.since(Time.at(0)).to_i }
|
66
|
-
#
|
67
|
-
def expiry=(expiry)
|
68
|
-
raise ArgumentError, 'Must be a callable' unless expiry.respond_to?(:call)
|
69
|
-
@expiry = expiry
|
70
|
-
end
|
71
|
-
|
72
|
-
# @private
|
73
|
-
def expiry
|
74
|
-
@expiry ||= -> { Time.zone.now.to_i + 600 }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module FilepickerRails
|
2
|
-
# @private
|
3
|
-
class Engine < ::Rails::Engine
|
4
|
-
config.filepicker_rails = FilepickerRails::Configuration.new
|
5
|
-
isolate_namespace FilepickerRails
|
6
|
-
|
7
|
-
initializer "filepicker_rails.form_builder" do
|
8
|
-
ActionView::Helpers::FormBuilder.send(:include, FilepickerRails::FormHelper)
|
9
|
-
end
|
10
|
-
|
11
|
-
initializer 'filepicker_rails.action_controller' do |app|
|
12
|
-
ActiveSupport.on_load(:action_controller) do
|
13
|
-
::ActionController::Base.helper(FilepickerRails::ApplicationHelper)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'openssl'
|
3
|
-
|
4
|
-
module FilepickerRails
|
5
|
-
class Policy
|
6
|
-
attr_accessor :expiry, :call, :handle, :maxsize, :minsize, :path
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
[:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
|
10
|
-
send("#{input}=", options[input]) unless options[input].nil?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def policy
|
15
|
-
Base64.urlsafe_encode64(json_policy)
|
16
|
-
end
|
17
|
-
|
18
|
-
def signature
|
19
|
-
OpenSSL::HMAC.hexdigest('sha256', ::Rails.application.config.filepicker_rails.secret_key, policy)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.apply(call: [:read, :convert], keys: ['policy', 'signature'], options: {})
|
23
|
-
return {} unless ::Rails.application.config.filepicker_rails.secret_key.present?
|
24
|
-
grant = Policy.new(options)
|
25
|
-
grant.call = call
|
26
|
-
{
|
27
|
-
keys[0] => grant.policy,
|
28
|
-
keys[1] => grant.signature
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def json_policy
|
34
|
-
hash = Hash.new
|
35
|
-
|
36
|
-
@expiry ||= ::Rails.application.config.filepicker_rails.expiry.call
|
37
|
-
|
38
|
-
[:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
|
39
|
-
hash[input] = send(input) unless send(input).nil?
|
40
|
-
end
|
41
|
-
|
42
|
-
hash.to_json
|
43
|
-
end
|
44
|
-
end
|
45
|
-
private_constant :Policy
|
46
|
-
end
|
data/lib/filepicker_rails/tag.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module FilepickerRails
|
2
|
-
# @private
|
3
|
-
module Tag
|
4
|
-
|
5
|
-
FILEPICKER_OPTIONS_TO_DASHERIZE = [:button_text, :button_class, :mimetypes,
|
6
|
-
:extensions, :container, :services,
|
7
|
-
:drag_text, :drag_class, :store_path,
|
8
|
-
:store_location, :store_access,
|
9
|
-
:store_container, :multiple]
|
10
|
-
|
11
|
-
FILEPICKER_OPTIONS_TO_CAMELIZE = [:max_size, :max_files, :open_to, :language]
|
12
|
-
|
13
|
-
private
|
14
|
-
attr_reader :input_options, :type
|
15
|
-
|
16
|
-
def define_input_options(options)
|
17
|
-
@type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
|
18
|
-
@input_options = retrieve_legacy_filepicker_options(options)
|
19
|
-
@input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
|
20
|
-
@input_options.merge!(secure_filepicker) unless @input_options['data-fp-policy'].present?
|
21
|
-
@input_options['type'] = @type
|
22
|
-
@input_options
|
23
|
-
end
|
24
|
-
|
25
|
-
def filepicker_prefix
|
26
|
-
'data-fp-'
|
27
|
-
end
|
28
|
-
|
29
|
-
def retrieve_legacy_filepicker_options(options)
|
30
|
-
mappings = {}
|
31
|
-
FILEPICKER_OPTIONS_TO_DASHERIZE.each do |option|
|
32
|
-
mappings[option] = "#{filepicker_prefix}#{option.to_s.dasherize}"
|
33
|
-
end
|
34
|
-
FILEPICKER_OPTIONS_TO_CAMELIZE.each do |option|
|
35
|
-
mappings[option] = "#{filepicker_prefix}#{option.to_s.camelize(:lower)}"
|
36
|
-
end
|
37
|
-
Hash[options.map {|k, v| [mappings[k] || k, v] }]
|
38
|
-
end
|
39
|
-
|
40
|
-
def secure_filepicker
|
41
|
-
Policy.apply(call: [:pick, :store], keys: ['data-fp-policy', 'data-fp-signature'])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|