rails-uploader 0.5.0 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/Rakefile +2 -1
- data/app/controllers/uploader/attachments_controller.rb +0 -6
- data/app/views/uploader/default/_container.html.erb +1 -0
- data/lib/uploader/authorization.rb +4 -2
- data/lib/uploader/helpers/field_tag.rb +9 -0
- data/lib/uploader/json_rendering.rb +11 -0
- data/lib/uploader/version.rb +1 -1
- data/spec/dummy/app/uploaders/picture_uploader.rb +1 -3
- data/vendor/assets/javascripts/uploader/jquery.fileupload-ui.js +5 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 566c841fcb9d098a1b256c3aff94e01950cdbb0ace03d1c657e8d9fa3c114314
|
4
|
+
data.tar.gz: 4ac9416e87c31176a81392e1a958fc90e65f3cc5c70d7faf72e37fdadcb21053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d535a4a9a2c9e40d24826c586f6ebf006934f3194f4600390e783659eadbe37955474b8430a1843ed8db6841afc13998cbaf46e2b935a88bc651fccf8806f33c
|
7
|
+
data.tar.gz: 1ddd6948b2fd9c202b1a1bfeb9ce491964823bd7a3b861a33f2ad34b7c7e09fd6b452c1b5da312344ccdc9f9de1c6b8f8e42c45a2bcd40489f872f4fedf2e322
|
data/README.md
CHANGED
@@ -41,6 +41,23 @@ class Picture < Asset
|
|
41
41
|
url(:thumb)
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
class PictureUploader < CarrierWave::Uploader::Base
|
46
|
+
include CarrierWave::MiniMagick
|
47
|
+
|
48
|
+
# Choose what kind of storage to use for this uploader:
|
49
|
+
storage :file
|
50
|
+
|
51
|
+
EXTENSION_WHITELIST = %w[jpg jpeg gif png].freeze
|
52
|
+
|
53
|
+
version :thumb do
|
54
|
+
process resize_to_fill: [100, 100]
|
55
|
+
end
|
56
|
+
|
57
|
+
def extension_whitelist
|
58
|
+
EXTENSION_WHITELIST
|
59
|
+
end
|
60
|
+
end
|
44
61
|
```
|
45
62
|
|
46
63
|
For example user has one picture:
|
data/Rakefile
CHANGED
@@ -69,12 +69,6 @@ module Uploader
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
def render_json(hash_or_object, status = 200)
|
73
|
-
self.status = status
|
74
|
-
self.content_type = request.format
|
75
|
-
self.response_body = hash_or_object.to_json(root: false)
|
76
|
-
end
|
77
|
-
|
78
72
|
def asset_params
|
79
73
|
ActionController::Parameters.new(params).require(:asset).permit(:data)
|
80
74
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<%= content_tag(:div, id: field.id, class: 'uploader-dnd-area', data: { tpml: field.klass.to_s, exists: field.exists? }) do -%>
|
2
2
|
<%= hidden_field(field.object_name, :fileupload_guid, object: field.object) if field.object.new_record? %>
|
3
3
|
|
4
|
+
<p class='uploader-errors'></p>
|
4
5
|
<div class="uploader-files"></div>
|
5
6
|
|
6
7
|
<div class="uploader-dnd-hints">
|
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
|
+
require_relative 'json_rendering'
|
4
5
|
|
5
6
|
module Uploader
|
6
7
|
module Authorization
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
|
9
10
|
included do
|
10
|
-
include
|
11
|
+
include JsonRendering
|
12
|
+
include ActionController::Rescue
|
11
13
|
|
12
14
|
rescue_from Uploader::AccessDenied, with: :dispatch_uploader_access_denied
|
13
15
|
end
|
@@ -44,7 +46,7 @@ module Uploader
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def dispatch_uploader_access_denied(exception)
|
47
|
-
|
49
|
+
render_json({ message: exception.message }, 403)
|
48
50
|
end
|
49
51
|
|
50
52
|
def current_uploader_user
|
@@ -76,12 +76,21 @@ module Uploader
|
|
76
76
|
@input_html ||= { multiple: multiple?, class: 'uploader' }.merge(input_html_options)
|
77
77
|
@input_html[:data] ||= {}
|
78
78
|
@input_html[:data][:url] ||= attachments_path(singular: !multiple?)
|
79
|
+
@input_html[:accept] ||= extract_extension_whitelist
|
79
80
|
@input_html
|
80
81
|
end
|
81
82
|
|
82
83
|
def input_html_options
|
83
84
|
@options.reject { |key, _value| RESERVED_OPTIONS_KEYS.include?(key.to_s) }
|
84
85
|
end
|
86
|
+
|
87
|
+
def extract_extension_whitelist
|
88
|
+
return unless klass.respond_to?(:uploaders)
|
89
|
+
return unless klass.uploaders[:data].try(:const_defined?, :EXTENSION_WHITELIST)
|
90
|
+
|
91
|
+
exts = klass.uploaders[:data]::EXTENSION_WHITELIST
|
92
|
+
".#{exts.join(', .')}" if exts.any?
|
93
|
+
end
|
85
94
|
end
|
86
95
|
end
|
87
96
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uploader
|
4
|
+
module JsonRendering
|
5
|
+
def render_json(hash_or_object, status = 200)
|
6
|
+
self.status = status
|
7
|
+
self.content_type = request.format
|
8
|
+
self.response_body = hash_or_object.to_json(root: false)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/uploader/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class PictureUploader < CarrierWave::Uploader::Base
|
4
|
-
|
5
4
|
# Include RMagick or MiniMagick support:
|
6
5
|
# include CarrierWave::RMagick
|
7
6
|
include CarrierWave::MiniMagick
|
@@ -51,5 +50,4 @@ class PictureUploader < CarrierWave::Uploader::Base
|
|
51
50
|
# def filename
|
52
51
|
# "something.jpg" if original_filename
|
53
52
|
# end
|
54
|
-
|
55
53
|
end
|
@@ -173,6 +173,7 @@
|
|
173
173
|
deferred;
|
174
174
|
var options = that.options;
|
175
175
|
if (options.singular) { options.filesContainer.html(data.context || '') };
|
176
|
+
options.dropZone.find('.uploader-errors').text('');
|
176
177
|
if (data.context) {
|
177
178
|
data.context.each(function (index) {
|
178
179
|
var file = files[index] ||
|
@@ -220,6 +221,9 @@
|
|
220
221
|
$(this).data('fileupload'),
|
221
222
|
template,
|
222
223
|
deferred;
|
224
|
+
try { var errors = data._response.jqXHR.responseJSON.files[0].error || ''}
|
225
|
+
catch (e) { var errors = '' }
|
226
|
+
that.options.dropZone.find('.uploader-errors').text(errors);
|
223
227
|
if (data.context) {
|
224
228
|
data.context.each(function (index) {
|
225
229
|
if (data.errorThrown !== 'abort') {
|
@@ -239,6 +243,7 @@
|
|
239
243
|
that._trigger('failed', e, data);
|
240
244
|
that._trigger('finished', e, data);
|
241
245
|
deferred.resolve();
|
246
|
+
data.context.remove();
|
242
247
|
}
|
243
248
|
);
|
244
249
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Galeta
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: carrierwave
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: mongoid
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: sqlite3
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/uploader/hooks/active_record.rb
|
94
94
|
- lib/uploader/hooks/formtastic.rb
|
95
95
|
- lib/uploader/hooks/simple_form.rb
|
96
|
+
- lib/uploader/json_rendering.rb
|
96
97
|
- lib/uploader/upload_request.rb
|
97
98
|
- lib/uploader/version.rb
|
98
99
|
- spec/dummy/README.rdoc
|