effective_assets 1.9.4 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56e9391eeed760a355bd84613a40c4a12affb3c9
4
- data.tar.gz: 132a6b5b71a5e8acaab4159f224ec0f86ec705f9
3
+ metadata.gz: 20a77f1197fa8a7ccf0c56518e305fb23fa09625
4
+ data.tar.gz: 37aec983b5f2e971ab49f1bc15eb0df9d588f169
5
5
  SHA512:
6
- metadata.gz: f09f7b738e5dfd50f728ad08b7d8a4c5e83c37c68d5139400963b206f5e60b25991e9d603f9bc64ded3ef27387a01071ae43ee2a3ca8c20139f1d711f6177272
7
- data.tar.gz: 78bd86d0afa6a818cab1fea90da212beb5ecfb4a4a56635d2bc4a317090a0d2c9e608973643426f9e721ffe805db6854609d4c908eb40eb55debfe8c8f10902f
6
+ metadata.gz: 30d3b68cc22b7ae95feef14210b22bfe52f732d680e269129f05338db191125594549dca1bed2ef70063b027245e2e50792ff5d0f18597529b5d2e132b993da6
7
+ data.tar.gz: 46b1685339f2f3ea8d5f33106e29542c8318e7bb1504cdfddf456dac855954e72e390c6890167b8c43e511033c60316c10e1b6b33d91721b45828e03a1a42bd5
@@ -157,7 +157,7 @@ module Effective
157
157
  end
158
158
 
159
159
  def file_name
160
- upload_file.to_s.split('/').last rescue upload_file
160
+ upload_file.to_s.split('/').last.gsub(/\?.+/, '') rescue upload_file
161
161
  end
162
162
 
163
163
  def video?
@@ -205,7 +205,7 @@ module Effective
205
205
  self.remote_data_url = url
206
206
  else
207
207
  puts 'Non S3 Asset downloading and processing'
208
- puts 'Downloading #{asset.url}'
208
+ puts "Downloading #{upload_file}"
209
209
 
210
210
  self.remote_data_url = upload_file
211
211
  end
@@ -235,7 +235,7 @@ module Effective
235
235
 
236
236
  def set_content_type
237
237
  if [nil, 'null', 'unknown', 'application/octet-stream', ''].include?(content_type)
238
- self.content_type = case File.extname(file_name).downcase.gsub(/\?.+/, '')
238
+ self.content_type = case File.extname(file_name.to_s.downcase.gsub(/\?.+/, ''))
239
239
  when '.mp3' ; 'audio/mp3'
240
240
  when '.mp4' ; 'video/mp4'
241
241
  when '.mov' ; 'video/mov'
@@ -4,7 +4,7 @@ module Effective
4
4
  class Attachment < ActiveRecord::Base
5
5
  self.table_name = EffectiveAssets.attachments_table_name.to_s
6
6
 
7
- belongs_to :asset
7
+ belongs_to :asset, class_name: 'Effective::Asset'
8
8
  belongs_to :attachable, :polymorphic => true
9
9
 
10
10
  # structure do
@@ -29,7 +29,7 @@ EffectiveAssets.setup do |config|
29
29
  config.aws_bucket = '' # ENV.fetch('AWS_S3_BUCKET')
30
30
  config.aws_access_key_id = '' # ENV.fetch('AWS_ACCESS_KEY_ID')
31
31
  config.aws_secret_access_key = '' # ENV.fetch('AWS_SECRET_ACCESS_KEY')
32
- config.aws_region = 'us-east-1'
32
+ config.aws_region = 'us-east-1' # ENV.fetch('AWS_REGION') # ca-central-1
33
33
 
34
34
  config.aws_path = 'assets/'
35
35
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveAssets
2
- VERSION = '1.9.4'.freeze
2
+ VERSION = '1.9.5'.freeze
3
3
  end
@@ -93,4 +93,37 @@ namespace :effective_assets do
93
93
  end
94
94
  end
95
95
 
96
+ desc 'Download all'
97
+ task :download, [:start_at, :end_at, :version] => :environment do |t, args|
98
+ args.with_defaults(start_at: 1, end_at: Effective::Asset.unscoped.maximum(:id), version: nil)
99
+ args.version.gsub!(':', '') if args.version
100
+ ids = Range.new(args.start_at.to_i, args.end_at.to_i)
101
+
102
+ Dir.mkdir('downloads') unless File.exist?('downloads')
103
+
104
+ Effective::Asset.where(id: ids).find_each do |asset|
105
+ (GC.start rescue nil)
106
+
107
+ Dir.mkdir("downloads/#{asset.id}") unless File.exist?("downloads/#{asset.id}")
108
+
109
+ # This goes through all versions, and nil, the original file
110
+ ([nil] + Array(asset.data.try(:versions).try(:keys))).each do |version|
111
+ next unless (args.version.nil? || args.version == version.to_s)
112
+
113
+ url = URI(asset.url(version))
114
+ file_name = asset.public_url(version).to_s.split('/').last
115
+
116
+ begin
117
+ puts "downloading #{asset.id}/#{file_name}"
118
+
119
+ File.open("downloads/#{asset.id}/#{file_name}", 'wb') do |file|
120
+ file.write(open(url.to_s).read)
121
+ end
122
+ rescue => e
123
+ puts "ERROR: unable to download #{asset.id}/#{file_name} (#{url})"
124
+ end
125
+ end
126
+
127
+ end
128
+ end
96
129
  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.9.4
4
+ version: 1.9.5
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: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails