paperclip_upload 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +7 -4
- data/README.md +1 -14
- data/app/controllers/paperclip_upload/uploads_controller.rb +0 -12
- data/app/models/paperclip_upload/upload.rb +17 -9
- data/lib/generators/paperclip_upload/upload_controller/templates/controller.rb +0 -12
- data/lib/generators/paperclip_upload/upload_controller/upload_controller_generator.rb +2 -12
- data/lib/paperclip_upload/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab8ed12df64b54b310f81a3e0dc71002872e323
|
4
|
+
data.tar.gz: 83388e8f681debfac5c1687e5d5e0d1d2953b2ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95d919e913e76b7386a8a0ef36875f27baae052afc2ec48372df82faf2c2f8057081e5527f7f8c22d49b3366353a6b3fd98bcbb22ad9397263d382744a4e9eb
|
7
|
+
data.tar.gz: be4ef5c06bdbfa924ce2055567eb5fd515d6a27e442d9f806aecb9d90e2b56089637968cc163c02842ac4b4a092d33fcb060985c1217cc87c3636972cafeba76
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
### v1.2.3
|
6
|
+
|
7
|
+
##### Fixed
|
8
|
+
* Removed `uploads#download` endpoint. Use always `file.url` instead of `file.path`. `file.path` does not work with S3 config.
|
9
|
+
|
5
10
|
### v1.2.2
|
6
11
|
|
7
12
|
##### Fixed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paperclip_upload (1.2.
|
4
|
+
paperclip_upload (1.2.3)
|
5
5
|
active_model_serializers (~> 0.9.3)
|
6
6
|
hashids (~> 1.0, >= 1.0.2)
|
7
7
|
paperclip (~> 4.2, >= 4.2.0)
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
railties (>= 3.0.0)
|
70
70
|
ffi (1.9.8)
|
71
71
|
formatador (0.2.5)
|
72
|
-
globalid (0.3.
|
72
|
+
globalid (0.3.6)
|
73
73
|
activesupport (>= 4.1.0)
|
74
74
|
guard (2.12.5)
|
75
75
|
formatador (>= 0.2.4)
|
@@ -180,9 +180,9 @@ GEM
|
|
180
180
|
shoulda-matchers (2.8.0)
|
181
181
|
activesupport (>= 3.0.0)
|
182
182
|
slop (3.6.0)
|
183
|
-
sprockets (3.
|
183
|
+
sprockets (3.3.4)
|
184
184
|
rack (~> 1.0)
|
185
|
-
sprockets-rails (2.3.
|
185
|
+
sprockets-rails (2.3.3)
|
186
186
|
actionpack (>= 3.0)
|
187
187
|
activesupport (>= 3.0)
|
188
188
|
sprockets (>= 2.8, < 4.0)
|
@@ -208,3 +208,6 @@ DEPENDENCIES
|
|
208
208
|
rspec-rails (~> 3.2, >= 3.2.1)
|
209
209
|
shoulda-matchers (~> 2.8, >= 2.8.0)
|
210
210
|
sqlite3 (~> 1.3, >= 1.3.10)
|
211
|
+
|
212
|
+
BUNDLED WITH
|
213
|
+
1.10.6
|
data/README.md
CHANGED
@@ -181,14 +181,9 @@ class Api::UploadsController < Api::BaseController
|
|
181
181
|
|
182
182
|
def create
|
183
183
|
new_upload = PaperclipUpload::Upload.create(permitted_params)
|
184
|
-
set_download_url(new_upload)
|
185
184
|
respond_with new_upload, status: :created
|
186
185
|
end
|
187
186
|
|
188
|
-
def download
|
189
|
-
send_file(upload.file.path, type: upload.file_content_type, disposition: 'inline')
|
190
|
-
end
|
191
|
-
|
192
187
|
private
|
193
188
|
|
194
189
|
def permitted_params
|
@@ -198,21 +193,13 @@ class Api::UploadsController < Api::BaseController
|
|
198
193
|
def upload
|
199
194
|
@upload ||= PaperclipUpload::Upload.find_by_identifier(params[:identifier])
|
200
195
|
end
|
201
|
-
|
202
|
-
private
|
203
|
-
|
204
|
-
def set_download_url(_upload)
|
205
|
-
_upload.singleton_class.send(:attr_accessor, :download_url)
|
206
|
-
_upload.download_url = download_api_upload_url(identifier: _upload.identifier)
|
207
|
-
end
|
208
196
|
end
|
209
197
|
```
|
210
198
|
|
211
|
-
and the
|
199
|
+
and the route...
|
212
200
|
|
213
201
|
```ruby
|
214
202
|
post "api/uploads", to: "api/uploads#create", defaults: { format: :json }
|
215
|
-
get "api/uploads/:identifier/download", to: "api/uploads#download", defaults: { format: :json }, as: :download_api_upload
|
216
203
|
```
|
217
204
|
|
218
205
|
## Configuration
|
@@ -5,14 +5,9 @@ module PaperclipUpload
|
|
5
5
|
|
6
6
|
def create
|
7
7
|
new_upload = PaperclipUpload::Upload.create(permitted_params)
|
8
|
-
set_download_url(new_upload)
|
9
8
|
respond_with new_upload, status: :created
|
10
9
|
end
|
11
10
|
|
12
|
-
def download
|
13
|
-
send_file(upload.file.path, type: upload.file_content_type, disposition: 'inline')
|
14
|
-
end
|
15
|
-
|
16
11
|
private
|
17
12
|
|
18
13
|
def permitted_params
|
@@ -22,12 +17,5 @@ module PaperclipUpload
|
|
22
17
|
def upload
|
23
18
|
@upload ||= PaperclipUpload::Upload.find_by_identifier(params[:identifier])
|
24
19
|
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def set_download_url(_upload)
|
29
|
-
_upload.singleton_class.send(:attr_accessor, :download_url)
|
30
|
-
_upload.download_url = download_url(identifier: _upload.identifier)
|
31
|
-
end
|
32
20
|
end
|
33
21
|
end
|
@@ -15,24 +15,26 @@ module PaperclipUpload
|
|
15
15
|
class Upload < ActiveRecord::Base
|
16
16
|
IDENTIFIER_LENGTH = 8
|
17
17
|
|
18
|
-
has_attached_file :file,
|
18
|
+
has_attached_file :file,
|
19
|
+
path: ':rails_root/public/uploads/:identifier/:filename',
|
20
|
+
url: "/uploads/:identifier/:basename.:extension"
|
19
21
|
|
20
22
|
do_not_validate_attachment_file_type :file
|
21
23
|
validates_attachment_presence :file
|
22
24
|
|
23
25
|
def identifier
|
24
|
-
raise "valid with saved instance only" if
|
25
|
-
self.class.hashid.encode(
|
26
|
+
raise "valid with saved instance only" if id.blank?
|
27
|
+
self.class.hashid.encode(id)
|
26
28
|
end
|
27
29
|
|
28
30
|
def file_extension
|
29
|
-
return unless
|
30
|
-
File.extname(
|
31
|
+
return unless file.exists?
|
32
|
+
File.extname(file.original_filename).split('.').last
|
31
33
|
end
|
32
34
|
|
33
35
|
def file_name
|
34
|
-
return unless
|
35
|
-
|
36
|
+
return unless file.exists?
|
37
|
+
file_file_name.gsub(".#{file_extension}", "")
|
36
38
|
end
|
37
39
|
|
38
40
|
def self.find_by_identifier(_identifier)
|
@@ -40,14 +42,20 @@ module PaperclipUpload
|
|
40
42
|
PaperclipUpload::Upload.find(decoded_id)
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
def download_url
|
46
|
+
file.url
|
47
|
+
end
|
44
48
|
|
45
49
|
def self.hashid
|
46
50
|
Hashids.new(PaperclipUpload.hash_salt, IDENTIFIER_LENGTH)
|
47
51
|
end
|
48
52
|
|
49
53
|
def self.identifier_to_id(_identifier)
|
50
|
-
|
54
|
+
hashid.decode(_identifier).first
|
55
|
+
end
|
56
|
+
|
57
|
+
Paperclip.interpolates(:identifier) do |attachment, _|
|
58
|
+
attachment.instance.identifier
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -4,14 +4,9 @@ class UploadController < ApplicationController
|
|
4
4
|
|
5
5
|
def create
|
6
6
|
new_upload = PaperclipUpload::Upload.create(permitted_params)
|
7
|
-
set_download_url(new_upload)
|
8
7
|
respond_with new_upload, status: :created
|
9
8
|
end
|
10
9
|
|
11
|
-
def download
|
12
|
-
send_file(upload.file.path, type: upload.file_content_type, disposition: 'inline')
|
13
|
-
end
|
14
|
-
|
15
10
|
private
|
16
11
|
|
17
12
|
def permitted_params
|
@@ -21,11 +16,4 @@ class UploadController < ApplicationController
|
|
21
16
|
def upload
|
22
17
|
@upload ||= PaperclipUpload::Upload.find_by_identifier(params[:identifier])
|
23
18
|
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def set_download_url(_upload)
|
28
|
-
_upload.singleton_class.send(:attr_accessor, :download_url)
|
29
|
-
_upload.download_url = "download_link"
|
30
|
-
end
|
31
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class PaperclipUpload::UploadControllerGenerator < Rails::Generators::NamedBase
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
|
-
argument :base_controller, type: :string, :
|
3
|
+
argument :base_controller, type: :string, default: "application"
|
4
4
|
|
5
5
|
def generate_controller
|
6
6
|
generate "controller #{resource_path} --no-helper --no-assets --no-view-specs --no-controller-specs"
|
@@ -12,14 +12,9 @@ class PaperclipUpload::UploadControllerGenerator < Rails::Generators::NamedBase
|
|
12
12
|
|
13
13
|
def customize_controller
|
14
14
|
line = "class UploadController < ApplicationController"
|
15
|
-
gsub_file controller_path, /(#{Regexp.escape(line)})/mi do
|
15
|
+
gsub_file controller_path, /(#{Regexp.escape(line)})/mi do
|
16
16
|
"class #{controller_class} < #{base_controller_class}"
|
17
17
|
end
|
18
|
-
|
19
|
-
link = "\"download_link\""
|
20
|
-
gsub_file controller_path, /(#{Regexp.escape(link)})/mi do |match|
|
21
|
-
"#{download_route_method}_url(identifier: _upload.identifier)"
|
22
|
-
end
|
23
18
|
end
|
24
19
|
|
25
20
|
def add_routes
|
@@ -28,17 +23,12 @@ class PaperclipUpload::UploadControllerGenerator < Rails::Generators::NamedBase
|
|
28
23
|
<<-HERE.gsub(/^ {9}/, '')
|
29
24
|
#{match}
|
30
25
|
post "#{resource_path}", to: "#{resource_path}#create", defaults: { format: :json }
|
31
|
-
get "#{resource_path}/:identifier/download", to: "#{resource_path}#download", defaults: { format: :json }, as: :#{download_route_method}
|
32
26
|
HERE
|
33
27
|
end
|
34
28
|
end
|
35
29
|
|
36
30
|
private
|
37
31
|
|
38
|
-
def download_route_method
|
39
|
-
"download_#{resource_path.singularize.gsub('/','_')}"
|
40
|
-
end
|
41
|
-
|
42
32
|
def controller_class
|
43
33
|
"#{name.classify.pluralize}Controller"
|
44
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Segovia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|