effective_assets 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +6 -18
- data/app/jobs/effective/process_with_active_job.rb +12 -0
- data/app/jobs/effective/process_with_sucker_punch_job.rb +15 -0
- data/app/models/effective/asset.rb +44 -14
- data/config/effective_assets.rb +3 -3
- data/lib/effective_assets/engine.rb +1 -1
- data/lib/effective_assets/version.rb +1 -1
- data/lib/effective_assets.rb +0 -1
- data/lib/generators/effective_assets/install_generator.rb +0 -3
- data/lib/tasks/effective_assets_tasks.rake +12 -15
- metadata +9 -9
- data/Rakefile +0 -23
- data/app/models/effective/delayed_job.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4203bea664bf1bdd6bb31fb866375a10a186b51b
|
4
|
+
data.tar.gz: 0d8792dd7b61066eb0e13d671d8c591c98052a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b36113a751f8240e1929663e61e9f91128f336746d3848002c9fd84c5fb6425f19dd74fafa3513089ed70dd96b169dc801579fdf8ba8ef4102abb96ad49d623
|
7
|
+
data.tar.gz: e49cb21cfc006dc6116098d85a64cedabf170ab0780a9753862f3f1770b4953ac0d8599ca4bc645a0cc3d15557ce8126be95e82be9ca41a83d4c4ea5e8e0329e
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -355,9 +355,11 @@ Has final say over the privacy setting when uploaded from this form.
|
|
355
355
|
|
356
356
|
### Image Processing and Resizing
|
357
357
|
|
358
|
-
CarrierWave
|
358
|
+
CarrierWave is used by this gem to perform image versioning.
|
359
359
|
|
360
|
-
|
360
|
+
All image processing is run asynchronously.
|
361
|
+
|
362
|
+
If there is a valid ActiveJob queue_adapter configured, it will be used. Otherwise we rely on the sucker_punch gem.
|
361
363
|
|
362
364
|
See the installer created at `app/uploaders/asset_uploader.rb` to configure image versions.
|
363
365
|
|
@@ -505,20 +507,6 @@ rake effective_assets:check[1,200] # check #1..#200
|
|
505
507
|
rake effective:assets:check[1,200,:thumb] # check #1..#200 only :thumb versions
|
506
508
|
```
|
507
509
|
|
508
|
-
### Clear
|
509
|
-
|
510
|
-
Deletes all effective_assets related jobs on the DelayedJob queue.
|
511
|
-
|
512
|
-
```ruby
|
513
|
-
rake effective_assets:clear
|
514
|
-
```
|
515
|
-
|
516
|
-
or to clear all jobs, even non-effective_assets related jobs, use DelayedJob's rake task:
|
517
|
-
|
518
|
-
```ruby
|
519
|
-
rake jobs:clear
|
520
|
-
```
|
521
|
-
|
522
510
|
## License
|
523
511
|
|
524
512
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -526,11 +514,11 @@ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
|
526
514
|
|
527
515
|
## Credits
|
528
516
|
|
529
|
-
This gem
|
517
|
+
This gem relies on:
|
530
518
|
|
531
519
|
CarrierWave (https://github.com/carrierwaveuploader/carrierwave)
|
532
520
|
|
533
|
-
|
521
|
+
sucker_punch (https://github.com/brandonhilkert/sucker_punch)
|
534
522
|
|
535
523
|
jQuery-File-Upload (https://github.com/blueimp/jQuery-File-Upload)
|
536
524
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Effective
|
2
|
+
class ProcessWithActiveJob < (defined?(ApplicationJob) ? ApplicationJob : ActiveJob::Base)
|
3
|
+
|
4
|
+
def perform(id)
|
5
|
+
ActiveRecord::Base.connection_pool.with_connection do
|
6
|
+
asset = id.kind_of?(Effective::Asset) ? id : Effective::Asset.where(id: (id.to_i rescue 0)).first
|
7
|
+
asset.process! if asset
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sucker_punch'
|
2
|
+
|
3
|
+
module Effective
|
4
|
+
class ProcessWithSuckerPunchJob
|
5
|
+
include ::SuckerPunch::Job
|
6
|
+
|
7
|
+
def perform(id)
|
8
|
+
ActiveRecord::Base.connection_pool.with_connection do
|
9
|
+
asset = id.kind_of?(Effective::Asset) ? id : Effective::Asset.where(id: (id.to_i rescue 0)).first
|
10
|
+
asset.process! if asset
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -51,7 +51,7 @@ module Effective
|
|
51
51
|
|
52
52
|
before_validation :set_content_type
|
53
53
|
before_save :update_asset_dimensions
|
54
|
-
|
54
|
+
after_commit :queue_async_job
|
55
55
|
|
56
56
|
default_scope -> { order(:id) }
|
57
57
|
scope :nonplaceholder, -> { where("#{EffectiveAssets.assets_table_name}.upload_file != ?", 'placeholder') }
|
@@ -78,7 +78,7 @@ module Effective
|
|
78
78
|
|
79
79
|
# Just call me with Asset.create_from_url('http://somewhere.com/somthing.jpg')
|
80
80
|
def create_from_url(url, options = {})
|
81
|
-
opts = {:
|
81
|
+
opts = { upload_file: url, user_id: 1, aws_acl: EffectiveAssets.aws_acl }.merge(options)
|
82
82
|
|
83
83
|
attempts = 3 # Try to upload this string file 3 times
|
84
84
|
begin
|
@@ -104,7 +104,7 @@ module Effective
|
|
104
104
|
|
105
105
|
filename = URI.escape(filename).gsub(/%\d\d|[^a-zA-Z0-9.-]/, '_') # Replace anything not A-Z, a-z, 0-9, . -
|
106
106
|
|
107
|
-
opts = {:
|
107
|
+
opts = { upload_file: "#{Asset.string_base_path}#{filename}", user_id: 1, aws_acl: EffectiveAssets.aws_acl }.merge(options)
|
108
108
|
|
109
109
|
attempts = 3 # Try to upload this string file 3 times
|
110
110
|
begin
|
@@ -157,11 +157,11 @@ module Effective
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def video?
|
160
|
-
content_type.include? 'video'
|
160
|
+
content_type.include? 'video/'
|
161
161
|
end
|
162
162
|
|
163
163
|
def image?
|
164
|
-
content_type.include? 'image'
|
164
|
+
content_type.include? 'image/'
|
165
165
|
end
|
166
166
|
|
167
167
|
def icon?
|
@@ -169,7 +169,7 @@ module Effective
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def audio?
|
172
|
-
content_type.include? 'audio'
|
172
|
+
content_type.include? 'audio/'
|
173
173
|
end
|
174
174
|
|
175
175
|
def versions_info
|
@@ -180,15 +180,41 @@ module Effective
|
|
180
180
|
title
|
181
181
|
end
|
182
182
|
|
183
|
+
def placeholder?
|
184
|
+
upload_file.blank? || upload_file == 'placeholder'.freeze
|
185
|
+
end
|
186
|
+
|
187
|
+
# This method is called asynchronously by an after_commit filter
|
183
188
|
def process!
|
189
|
+
# Make sure carrierwave-aws sets the correct permissions
|
184
190
|
if data.respond_to?(:aws_acl) && aws_acl.present?
|
185
|
-
data.aws_acl =
|
186
|
-
data.versions.each { |_, data| data.aws_acl =
|
191
|
+
data.aws_acl = aws_acl
|
192
|
+
data.versions.each { |_, data| data.aws_acl = aws_acl }
|
187
193
|
end
|
188
194
|
|
189
|
-
|
190
|
-
|
191
|
-
|
195
|
+
if placeholder?
|
196
|
+
puts 'Placeholder Asset processing not required (this is a soft error)'
|
197
|
+
# Do nothing
|
198
|
+
elsif image? == false
|
199
|
+
puts 'Non-image Asset processing not required'
|
200
|
+
# Do Nothing
|
201
|
+
elsif upload_file.include?(Effective::Asset.string_base_path)
|
202
|
+
puts 'String-based Asset processing and uploading'
|
203
|
+
|
204
|
+
data.cache_stored_file!
|
205
|
+
data.retrieve_from_cache!(data.cache_name)
|
206
|
+
data.recreate_versions!
|
207
|
+
elsif upload_file.include?(Effective::Asset.s3_base_path)
|
208
|
+
# Carrierwave must download the file, process it, then upload the generated versions to S3
|
209
|
+
puts 'S3 Uploaded Asset downloading and processing'
|
210
|
+
|
211
|
+
self.remote_data_url = url
|
212
|
+
else
|
213
|
+
puts 'Non S3 Asset downloading and processing'
|
214
|
+
puts 'Downloading #{asset.url}'
|
215
|
+
|
216
|
+
self.remote_data_url = upload_file
|
217
|
+
end
|
192
218
|
|
193
219
|
self.processed = true
|
194
220
|
save!
|
@@ -235,9 +261,13 @@ module Effective
|
|
235
261
|
true
|
236
262
|
end
|
237
263
|
|
238
|
-
def
|
239
|
-
if
|
240
|
-
|
264
|
+
def queue_async_job
|
265
|
+
return if processed? || placeholder?
|
266
|
+
|
267
|
+
if [:inline, :async, nil].include?((Rails.application.config.active_job[:queue_adapter] rescue nil))
|
268
|
+
Effective::ProcessWithSuckerPunchJob.perform_async(id)
|
269
|
+
else
|
270
|
+
Effective::ProcessWithActiveJob.perform_later(id)
|
241
271
|
end
|
242
272
|
end
|
243
273
|
end
|
data/config/effective_assets.rb
CHANGED
@@ -26,9 +26,9 @@ EffectiveAssets.setup do |config|
|
|
26
26
|
config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
|
27
27
|
|
28
28
|
# This is your S3 bucket information
|
29
|
-
config.aws_bucket = ''
|
30
|
-
config.aws_access_key_id = ''
|
31
|
-
config.aws_secret_access_key = ''
|
29
|
+
config.aws_bucket = '' # ENV.fetch('AWS_S3_BUCKET')
|
30
|
+
config.aws_access_key_id = '' # ENV.fetch('AWS_ACCESS_KEY_ID')
|
31
|
+
config.aws_secret_access_key = '' # ENV.fetch('AWS_SECRET_ACCESS_KEY')
|
32
32
|
config.aws_region = 'us-east-1'
|
33
33
|
|
34
34
|
config.aws_path = 'assets/'
|
@@ -2,7 +2,7 @@ module EffectiveAssets
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_assets'
|
4
4
|
|
5
|
-
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
|
5
|
+
config.autoload_paths += Dir["#{config.root}/app/models/**/", "#{config.root}/app/jobs/**/"]
|
6
6
|
|
7
7
|
# Include Helpers to base application
|
8
8
|
initializer 'effective_assets.action_controller' do |app|
|
data/lib/effective_assets.rb
CHANGED
@@ -29,9 +29,6 @@ module EffectiveAssets
|
|
29
29
|
migration_template ('../' * 3) + 'db/migrate/01_create_effective_assets.rb.erb', 'db/migrate/create_effective_assets.rb'
|
30
30
|
end
|
31
31
|
|
32
|
-
def install_delayed_jobs
|
33
|
-
run 'rails generate delayed_job:active_record'
|
34
|
-
end
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -2,31 +2,34 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
namespace :effective_assets do
|
4
4
|
|
5
|
-
# rake
|
5
|
+
# rake effective_assets:reprocess
|
6
6
|
#
|
7
7
|
# To reprocess every Asset: rake reprocess_assets
|
8
8
|
# Or reprocess from ID=100 and up: rake reprocess_assets[100]
|
9
9
|
# Or reprocess from ID=100 to 200: rake reprocess_assets[100,200]
|
10
10
|
|
11
|
-
|
11
|
+
desc "Reprocesses Effective::Assets and re-generates versions as per the current app/uploaders/asset_uploader.rb"
|
12
12
|
task :reprocess, [:start_at, :end_at] => :environment do |t, args|
|
13
13
|
args.with_defaults(:start_at => 1, :end_at => Effective::Asset.unscoped.maximum(:id))
|
14
14
|
ids = Range.new(args.start_at.to_i, args.end_at.to_i)
|
15
15
|
|
16
|
-
puts
|
16
|
+
puts 'Reprocessing assets...'
|
17
17
|
|
18
|
-
Effective::Asset.where(:
|
19
|
-
|
18
|
+
Effective::Asset.where(processed: true).where(id: ids).find_each do |asset|
|
19
|
+
begin
|
20
|
+
asset.reprocess!
|
21
|
+
puts "Successfully reprocessed ##{asset.id}"
|
22
|
+
rescue => e
|
23
|
+
puts "Error reprocessing ##{asset.id}: #{e.message}"
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
|
-
puts
|
23
|
-
puts "If a worker process is running, the reprocessing will have already begun."
|
24
|
-
puts "If not, run 'rake jobs:work' to begin the worker process now."
|
27
|
+
puts 'Done'
|
25
28
|
end
|
26
29
|
|
27
30
|
# This is going to pull all the versions and check every url manually
|
28
31
|
|
29
|
-
# rake
|
32
|
+
# rake rake effective_assets:check
|
30
33
|
#
|
31
34
|
# Checks the actual HTTP response code of the URL for each asset version
|
32
35
|
#
|
@@ -90,10 +93,4 @@ namespace :effective_assets do
|
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
93
|
-
desc "Deletes all effective_asset related Delayed::Job jobs"
|
94
|
-
task :clear => :environment do |t, args|
|
95
|
-
Delayed::Job.where('handler ILIKE ?', '%method_name: :process_asset_without_delay%').delete_all
|
96
|
-
Delayed::Job.where('handler ILIKE ?', '%method_name: :reprocess_asset_without_delay%').delete_all
|
97
|
-
puts 'Deleted all effective_asset related Delayed::Job jobs'
|
98
|
-
end
|
99
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: jquery-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: haml-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: sass-rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: sucker_punch
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -146,7 +146,6 @@ extra_rdoc_files: []
|
|
146
146
|
files:
|
147
147
|
- MIT-LICENSE
|
148
148
|
- README.md
|
149
|
-
- Rakefile
|
150
149
|
- active_admin/effective_assets.rb
|
151
150
|
- app/assets/images/effective_assets/icon_close.png
|
152
151
|
- app/assets/images/effective_assets/spinner.gif
|
@@ -178,11 +177,12 @@ files:
|
|
178
177
|
- app/controllers/effective/s3_uploads_controller.rb
|
179
178
|
- app/helpers/effective_assets_helper.rb
|
180
179
|
- app/helpers/effective_assets_s3_helper.rb
|
180
|
+
- app/jobs/effective/process_with_active_job.rb
|
181
|
+
- app/jobs/effective/process_with_sucker_punch_job.rb
|
181
182
|
- app/models/concerns/acts_as_asset_box.rb
|
182
183
|
- app/models/effective/access_denied.rb
|
183
184
|
- app/models/effective/asset.rb
|
184
185
|
- app/models/effective/attachment.rb
|
185
|
-
- app/models/effective/delayed_job.rb
|
186
186
|
- app/models/effective/iframe_uploads.rb
|
187
187
|
- app/models/effective/snippets/effective_asset.rb
|
188
188
|
- app/models/inputs/asset_box.rb
|
@@ -236,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
238
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.4.
|
239
|
+
rubygems_version: 2.4.5.1
|
240
240
|
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: Upload images and files directly to AWS S3 with a custom form input then
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
|
8
|
-
# Our tasks
|
9
|
-
load 'lib/tasks/effective_assets_tasks.rake'
|
10
|
-
|
11
|
-
# Testing tasks
|
12
|
-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
13
|
-
load 'rails/tasks/engine.rake'
|
14
|
-
|
15
|
-
Bundler::GemHelper.install_tasks
|
16
|
-
|
17
|
-
require 'rspec/core'
|
18
|
-
require 'rspec/core/rake_task'
|
19
|
-
|
20
|
-
desc "Run all specs in spec directory (excluding plugin specs)"
|
21
|
-
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
22
|
-
|
23
|
-
task :default => :spec
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# Call with DelayedJob.new.process_asset_images(...)
|
2
|
-
# Run jobs locally with "rake jobs:work"
|
3
|
-
|
4
|
-
module Effective
|
5
|
-
class DelayedJob
|
6
|
-
def process_asset(obj)
|
7
|
-
if obj.kind_of?(Effective::Asset)
|
8
|
-
asset = obj
|
9
|
-
else
|
10
|
-
asset = Effective::Asset.where(:id => (obj.to_i rescue 0)).first
|
11
|
-
end
|
12
|
-
|
13
|
-
if asset.present? && !asset.processed? && asset.upload_file.present? && asset.upload_file != 'placeholder'
|
14
|
-
puts "Processing asset ##{asset.id} from #{asset.upload_file}."
|
15
|
-
|
16
|
-
if asset.data.respond_to?(:aws_acl)
|
17
|
-
asset.data.aws_acl = asset.aws_acl
|
18
|
-
asset.data.versions.each { |_, data| data.aws_acl = asset.aws_acl }
|
19
|
-
end
|
20
|
-
|
21
|
-
if asset.upload_file.include?(Effective::Asset.string_base_path)
|
22
|
-
puts "String-based Asset processing and uploading..."
|
23
|
-
|
24
|
-
asset.data.cache_stored_file!
|
25
|
-
asset.data.retrieve_from_cache!(asset.data.cache_name)
|
26
|
-
asset.data.recreate_versions!
|
27
|
-
elsif asset.upload_file.include?(Effective::Asset.s3_base_path)
|
28
|
-
puts "S3 Uploaded Asset downloading and processing..."
|
29
|
-
# Carrierwave must download the file, process it, then upload the generated versions to S3
|
30
|
-
# We only want to process if it's an image, so we don't download zips or videos
|
31
|
-
asset.remote_data_url = asset.url if asset.image?
|
32
|
-
else
|
33
|
-
puts "Non S3 Asset downloading and processing..."
|
34
|
-
puts "Downloading #{asset.url}"
|
35
|
-
|
36
|
-
# Carrierwave must download the file, process it, then upload it and generated verions to S3
|
37
|
-
# We only want to process if it's an image, so we don't download zips or videos
|
38
|
-
asset.remote_data_url = asset.upload_file
|
39
|
-
end
|
40
|
-
|
41
|
-
asset.processed = true
|
42
|
-
asset.save!
|
43
|
-
|
44
|
-
(GC.start rescue nil)
|
45
|
-
|
46
|
-
puts "Successfully processed the asset."
|
47
|
-
end
|
48
|
-
end
|
49
|
-
handle_asynchronously :process_asset
|
50
|
-
|
51
|
-
def reprocess_asset(id)
|
52
|
-
Rails.logger.info "Processing ##{id}..."
|
53
|
-
print "Processing ##{id}..."
|
54
|
-
|
55
|
-
begin
|
56
|
-
Effective::Asset.find(id).reprocess!
|
57
|
-
|
58
|
-
Rails.logger.info "Successfully processed ##{id}"
|
59
|
-
print "success"; puts ''
|
60
|
-
rescue => e
|
61
|
-
Rails.logger.info "Error: #{id} -> #{e.to_s}"
|
62
|
-
print "error: #{e.to_s}"; puts ''
|
63
|
-
end
|
64
|
-
|
65
|
-
(GC.start rescue nil)
|
66
|
-
end
|
67
|
-
handle_asynchronously :reprocess_asset
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|