neofiles 1.3.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +0 -11
- data/app/controllers/neofiles/admin_controller.rb +5 -6
- data/app/controllers/neofiles/images_controller.rb +0 -1
- data/app/models/neofiles/data_store/amazon_s3.rb +7 -16
- data/app/views/neofiles/admin/_file_compact.html.haml +5 -9
- data/lib/neofiles/engine.rb +12 -9
- data/lib/neofiles/version.rb +1 -1
- data/lib/neofiles.rb +13 -15
- metadata +17 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6c91e9f6a9903c58776d7c916f8adda41c2694d
|
4
|
+
data.tar.gz: df2ede8d0562a3be9d2af8b3992eb4b662f9eb68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fafa7bbe4b172169631d83597b46348b8726d6a4d411ca9091b59412ee5810d5e9c249cdd30c08c1296f86107bd3e4a6550647e74d740683072bfa143011246
|
7
|
+
data.tar.gz: d34b9056fb7dad7faa2e1a1a94b0a90733718b4db25925b43fc9b85547ef0bc583c3ffd7a705e78f5fd7c02e9a1c76f50fb50162e49c8d1535c5aa938b09a920
|
data/README.md
CHANGED
@@ -403,17 +403,6 @@ config.neofiles.image_max_crop_height = 2000 # users can request resizing only u
|
|
403
403
|
config.neofiles.watermarker = ->(image, no_watermark: false, watermark_width:, watermark_height:) do
|
404
404
|
...
|
405
405
|
end
|
406
|
-
|
407
|
-
# picture when added is displayed on the right or left
|
408
|
-
# also affects the order of displaying pictures
|
409
|
-
config.neofiles.album_append_create_side = :left
|
410
|
-
|
411
|
-
# Amazon S3 settings
|
412
|
-
config.neofiles.amazon_s3_region = 'us-east'
|
413
|
-
config.neofiles.amazon_s3_api = 'KEY_ID'
|
414
|
-
config.neofiles.amazon_s3_secret = 'KEY_SECRET'
|
415
|
-
config.neofiles.amazon_s3_bucket = 'neofiles_prod'
|
416
|
-
config.neofiles.amazon_s3_endpoint = 'https://some-s3-provider.com' # optional
|
417
406
|
```
|
418
407
|
|
419
408
|
Roadmap, TODOs
|
@@ -9,7 +9,7 @@
|
|
9
9
|
class Neofiles::AdminController < ApplicationController
|
10
10
|
|
11
11
|
# TODO: remove this! it should be controlled on application side
|
12
|
-
|
12
|
+
skip_before_action :verify_authenticity_token
|
13
13
|
|
14
14
|
# Build AJAX edit/upload form for a single file in compact way: small file thumbnail + misc buttons, like "delete",
|
15
15
|
# "change options" etc.
|
@@ -107,15 +107,14 @@ class Neofiles::AdminController < ApplicationController
|
|
107
107
|
|
108
108
|
result = []
|
109
109
|
file_objects.each_with_index do |file, i|
|
110
|
-
|
111
|
-
result << file_compact(data.merge(id: file.id, widget_id: "#{data[:widget_id]}_ap_#{i}", append_create: append_create_position && !old_file && data[:append_create] == '1' ? '1' : '0'))
|
110
|
+
result << file_compact(data.merge(id: file.id, widget_id: "#{data[:widget_id]}_ap_#{i}", append_create: i == file_objects.count - 1 && !old_file && data[:append_create] == '1' ? '1' : '0'))
|
112
111
|
end
|
113
112
|
|
114
113
|
if result.empty?
|
115
114
|
raise ArgumentError.new(last_exception || (errors.empty? ? I18n.t('neofiles.file_not_passed') : errors.join("\n")))
|
116
115
|
end
|
117
116
|
|
118
|
-
render
|
117
|
+
render plain: result.join, layout: false
|
119
118
|
end
|
120
119
|
|
121
120
|
# As we don't actually delete anything, this method only marks file as deleted.
|
@@ -129,7 +128,7 @@ class Neofiles::AdminController < ApplicationController
|
|
129
128
|
file.is_deleted = true
|
130
129
|
file.save!
|
131
130
|
|
132
|
-
return render
|
131
|
+
return render plain: '' if data[:clean_remove].present? && data[:clean_remove] != '0'
|
133
132
|
|
134
133
|
redirect_to neofiles_file_compact_path(data.merge(id: nil))
|
135
134
|
end
|
@@ -141,7 +140,7 @@ class Neofiles::AdminController < ApplicationController
|
|
141
140
|
def file_update
|
142
141
|
file, data = find_file_and_data
|
143
142
|
file.update data.slice(:description, :no_wm)
|
144
|
-
render
|
143
|
+
render plain: '', layout: false
|
145
144
|
end
|
146
145
|
|
147
146
|
# Neofiles knows how to play with Redactor.js and this method persists files uploaded via this WYSIWYG editor.
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# If you want to work with amazon s3 you need set values for the following parameters in your config file
|
3
3
|
# amazon_s3_region - the AWS region to connect to. The region is used to construct the client endpoint.
|
4
4
|
# amazon_s3_api, amazon_s3_secret - used to set credentials statically
|
5
|
-
# amazon_s3_endpoint - change if using another S3-compatible provider
|
6
5
|
# bucket_name - storage name in amazon_s3. Bucket must have a name that conforms to the naming requirements for non-US Standard regions.
|
7
6
|
# http://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html
|
8
7
|
# File will be named as id of the Neofiles::File object
|
@@ -82,23 +81,15 @@ class Neofiles::DataStore::AmazonS3
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def client
|
85
|
-
@client ||= Aws::S3::Client.new(
|
84
|
+
@client ||= Aws::S3::Client.new(
|
85
|
+
region: Rails.application.config.neofiles.amazon_s3_region,
|
86
|
+
credentials: Aws::Credentials.new(
|
87
|
+
Rails.application.config.neofiles.amazon_s3_api,
|
88
|
+
Rails.application.config.neofiles.amazon_s3_secret
|
89
|
+
)
|
90
|
+
)
|
86
91
|
rescue Aws::S3::Errors::ServiceError
|
87
92
|
nil
|
88
93
|
end
|
89
94
|
|
90
|
-
def client_params
|
91
|
-
{
|
92
|
-
region: Rails.application.config.neofiles.amazon_s3_region,
|
93
|
-
credentials: Aws::Credentials.new(
|
94
|
-
Rails.application.config.neofiles.amazon_s3_api,
|
95
|
-
Rails.application.config.neofiles.amazon_s3_secret
|
96
|
-
)
|
97
|
-
}.tap do |result|
|
98
|
-
if Rails.application.config.neofiles.amazon_s3_endpoint
|
99
|
-
result[:endpoint] = Rails.application.config.neofiles.amazon_s3_endpoint
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
95
|
end
|
@@ -2,10 +2,6 @@
|
|
2
2
|
- desc = file.try(:description).try(:to_s).try!(:strip).try!(:truncate, 15).presence
|
3
3
|
- empty_desc = t 'neofiles.views.no_description'
|
4
4
|
|
5
|
-
- if Rails.application.config.neofiles.album_append_create_side == :left
|
6
|
-
- if append_create && file
|
7
|
-
= render partial: 'file_compact', locals: {file: nil, input_name: input_name, widget_id: widget_id + '_ap', clean_remove: clean_remove, append_create: true, error: nil, disabled: disabled, multiple: multiple, with_desc: with_desc, no_wm: no_wm}
|
8
|
-
|
9
5
|
- classes = []
|
10
6
|
- classes << 'neofiles-image-compact-empty' unless file
|
11
7
|
- classes << 'neofiles-image-compact-with-description' if file && with_desc
|
@@ -26,7 +22,7 @@
|
|
26
22
|
- if file.description.present?
|
27
23
|
%p= file.description
|
28
24
|
|
29
|
-
%p= t 'neofiles.views.created_at', local_date: l(file.created_at, format: t('neofiles.views.local_date_format'))
|
25
|
+
%p= raw t 'neofiles.views.created_at', local_date: l(file.created_at, format: t('neofiles.views.local_date_format'))
|
30
26
|
|
31
27
|
- file_options = []
|
32
28
|
- if file.respond_to? :dimensions
|
@@ -44,7 +40,7 @@
|
|
44
40
|
= check_box_tag uniq_name, '1', file.no_wm, class: 'neofiles-image-compact-nowm', data: {update_url: neofiles_file_update_path}
|
45
41
|
= t 'neofiles.views.no_wm'
|
46
42
|
|
47
|
-
%a(href="#" tabindex="0" class="neofiles-image-compact-options" data-toggle="popover" data-trigger="click" data-placement="top" data-html="true" data-animation="false" data-title="#{file.filename}" data-content=options_form)
|
43
|
+
%a(href="#" tabindex="0" class="neofiles-image-compact-options" data-toggle="popover" data-trigger="click" data-placement="top" data-html="true" data-animation="false" data-title="#{file.filename}" data-content="#{options_form}")
|
48
44
|
%i.icon-wrench.glyphicon.glyphicon-wrench
|
49
45
|
|
50
46
|
- if with_desc
|
@@ -86,6 +82,6 @@
|
|
86
82
|
$("##{widget_id}").image();
|
87
83
|
});
|
88
84
|
|
89
|
-
- if
|
90
|
-
|
91
|
-
|
85
|
+
- if append_create and file
|
86
|
+
= render partial: 'file_compact', locals: {file: nil, input_name: input_name, widget_id: widget_id + '_ap', clean_remove: clean_remove, append_create: true, error: nil, disabled: disabled, multiple: multiple, with_desc: with_desc, no_wm: no_wm}
|
87
|
+
|
data/lib/neofiles/engine.rb
CHANGED
@@ -16,20 +16,23 @@ module Neofiles
|
|
16
16
|
config.neofiles.image_max_crop_width = 2000 # users can request resizing only up to this width
|
17
17
|
config.neofiles.image_max_crop_height = 2000 # users can request resizing only up to this height
|
18
18
|
|
19
|
-
|
19
|
+
# default storage
|
20
|
+
config.neofiles.write_data_stores = 'mongo'
|
21
|
+
config.neofiles.read_data_stores = 'mongo'
|
20
22
|
|
21
23
|
# default watermarker — redefine to set special watermarking logic
|
22
24
|
# by default, watermark only images larger than 300x300 with watermark at the bottom center, taken from file
|
23
25
|
# /app/assets/images/neofiles/watermark.png
|
24
|
-
config.neofiles.watermarker = ->(
|
25
|
-
if
|
26
|
-
return image.to_blob
|
27
|
-
end
|
26
|
+
config.neofiles.watermarker = ->(convert, _image, width, height) {
|
27
|
+
return if width < 300 || height < 300
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
wm_path = Rails.root.join('app', 'assets', 'images', 'neofiles', 'watermark.png')
|
30
|
+
return unless ::File.exists?(wm_path)
|
31
|
+
|
32
|
+
convert << wm_path
|
33
|
+
convert.gravity 'south'
|
34
|
+
convert.geometry '200x+0+20'
|
35
|
+
convert.composite
|
33
36
|
}
|
34
37
|
end
|
35
38
|
end
|
data/lib/neofiles/version.rb
CHANGED
data/lib/neofiles.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'neofiles/engine'
|
2
|
-
require 'aspect_ratio'
|
3
2
|
|
4
3
|
module Neofiles
|
5
4
|
# Attach Neofiles specific routes in your routes.rb file:
|
@@ -35,6 +34,8 @@ module Neofiles
|
|
35
34
|
# width, height - max width and height after resize
|
36
35
|
# resize_options - {crop: '1'/'0'}, @see Neofiles::ImagesController#show
|
37
36
|
#
|
37
|
+
# Can call ImageMagick.
|
38
|
+
#
|
38
39
|
def resized_image_dimensions(image_file, width, height, resize_options)
|
39
40
|
# dimensions are equal to requested ones if cropping
|
40
41
|
return width, height if crop_requested? resize_options
|
@@ -57,20 +58,17 @@ module Neofiles
|
|
57
58
|
# image fits into requested dimensions, no resizing will occur
|
58
59
|
return image_file_width, image_file_height if image_file_width <= width && image_file_height <= height
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
AspectRatio.resize(image_file_width, image_file_height, width, height).map(&:to_i)
|
61
|
+
# ... construct request ...
|
62
|
+
command = MiniMagick::CommandBuilder.new(:convert) # convert input file...
|
63
|
+
command.size([image_file_width, image_file_height].join 'x') # with the given dimensions...
|
64
|
+
command.xc('white') # and filled with whites...
|
65
|
+
command.resize([width, height].join 'x') # to fit in the given rectangle...
|
66
|
+
command.push('info:-') # return info about the resulting file
|
67
|
+
|
68
|
+
# ... and send it to ImageMagick
|
69
|
+
# the result will be: xc:white XC 54x100 54x100+0+0 16-bit DirectClass 0.070u 0:00.119
|
70
|
+
# extract dimensions and return them as array of integers
|
71
|
+
MiniMagick::Image.new(nil, nil).run(command).match(/ (\d+)x(\d+) /).values_at(1, 2).map(&:to_i)
|
74
72
|
|
75
73
|
rescue
|
76
74
|
nil
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neofiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konanykhin Ilya
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongoid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-imagespec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: aspect_ratio
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
96
|
+
version: '2'
|
111
97
|
description: 'Library for managing files: creating & storing, linking to file owners,
|
112
98
|
serving files from MongoDB'
|
113
99
|
email:
|
@@ -155,7 +141,7 @@ homepage: http://neoweb.kz
|
|
155
141
|
licenses:
|
156
142
|
- MIT
|
157
143
|
metadata: {}
|
158
|
-
post_install_message:
|
144
|
+
post_install_message:
|
159
145
|
rdoc_options: []
|
160
146
|
require_paths:
|
161
147
|
- lib
|
@@ -170,8 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
156
|
- !ruby/object:Gem::Version
|
171
157
|
version: '0'
|
172
158
|
requirements: []
|
173
|
-
|
174
|
-
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.6.12
|
161
|
+
signing_key:
|
175
162
|
specification_version: 4
|
176
163
|
summary: Serves and manages files & images.
|
177
164
|
test_files: []
|