fclay 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/fclay/attachment.rb +59 -60
- data/lib/fclay/version.rb +1 -1
- data/lib/generators/fclay/templates/fclay_migration.rb.erb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab6904daef5ad6af4ee6d8dc265cd731298d2ba
|
4
|
+
data.tar.gz: 8b99722c842ef393c41307b1c8d3695768b19b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77783239ea607673a91fe65b3ca69105b4073ecd4bae284cdfacfa074f5ba5e060e7f223cf64ef13b8e39fe60591398a4805f50a75575b8d698b9c956f3ef49b
|
7
|
+
data.tar.gz: 4cf19d2e0c08dcbc5d0f29b5cca672a71e544b608721632970311d1d4f7602dc41605f4c37931a9c23d8d32da8428c66184cd1996c6caf4b6534f1e186574b20
|
data/README.md
CHANGED
data/lib/fclay/attachment.rb
CHANGED
@@ -1,70 +1,70 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
|
-
module Fclay
|
3
|
+
module Fclay
|
4
4
|
module Attachment
|
5
5
|
|
6
6
|
extend ActiveSupport::Concern
|
7
|
-
|
7
|
+
|
8
8
|
CALLBACKS = [:process,:upload,:delete]
|
9
|
-
|
10
|
-
|
11
|
-
included do
|
12
|
-
|
9
|
+
|
10
|
+
|
11
|
+
included do
|
12
|
+
|
13
13
|
callbacks = CALLBACKS
|
14
|
-
|
14
|
+
|
15
15
|
case fclay_options[:without].class.name
|
16
16
|
when "Symbol"
|
17
17
|
callbacks.clear if fclay_options[:without] == :all
|
18
18
|
when "Array"
|
19
19
|
callbacks -= fclay_options[:without]
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
21
|
+
|
22
22
|
before_save :process_file if callbacks.include? :process
|
23
23
|
after_save :process_upload if callbacks.include? :upload
|
24
24
|
before_destroy :delete_files if callbacks.include? :delete
|
25
|
-
|
25
|
+
|
26
26
|
end
|
27
27
|
|
28
28
|
attr_accessor :file
|
29
|
-
|
29
|
+
|
30
30
|
def delete_files
|
31
|
-
|
32
|
-
case self.file_location
|
31
|
+
|
32
|
+
case self.file_location
|
33
33
|
when 's3'
|
34
34
|
delete_remote_files
|
35
35
|
when 'local'
|
36
36
|
delete_local_files
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def process_upload
|
42
42
|
return unless need_upload
|
43
|
-
if self.class.fclay_options[:processing] == :foreground
|
43
|
+
if self.class.fclay_options[:processing] == :foreground
|
44
44
|
upload
|
45
45
|
else
|
46
46
|
upload_later
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def need_upload
|
51
51
|
Fclay.configuration.storage_policy != :local && self.file_location == "local"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def upload_later
|
55
|
-
|
55
|
+
|
56
56
|
self.try(:log,"upload_later() called, need_upload: #{need_upload}")
|
57
57
|
if need_upload
|
58
|
-
job = Fclay::UploadJob.perform_later(self.class.name,self.id)
|
58
|
+
job = Fclay::UploadJob.perform_later(self.class.name,self.id)
|
59
59
|
self.try(:log,"sheduled! job id: #{job.provider_job_id}")
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def upload
|
65
65
|
Fclay::Attachment.upload self.class.name,self.id
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def self.upload type,id
|
69
69
|
type = type.safe_constantize
|
70
70
|
return unless type
|
@@ -73,7 +73,7 @@ module Fclay
|
|
73
73
|
return if !uploading_object || !uploading_object.need_upload
|
74
74
|
content_type = uploading_object.try(:content_type)
|
75
75
|
bucket = Fclay.remote_storage.bucket_object
|
76
|
-
|
76
|
+
|
77
77
|
uploading_object.try(:log,"Start uploading")
|
78
78
|
(uploading_object.class.fclay_options[:styles] || [nil]).each do |style|
|
79
79
|
obj = bucket.object(uploading_object.remote_file_path(style))
|
@@ -88,7 +88,7 @@ module Fclay
|
|
88
88
|
uploading_object.try(:log,"Sucessful uploaded! file_status: 'idle', file_location: #{Fclay.remote_storage.name}")
|
89
89
|
uploading_object.delete_local_files
|
90
90
|
uploading_object.try(:uploaded)
|
91
|
-
|
91
|
+
|
92
92
|
|
93
93
|
end
|
94
94
|
|
@@ -96,9 +96,9 @@ module Fclay
|
|
96
96
|
errors.add(:file, 'must be present') if id.blank? && !@file
|
97
97
|
end
|
98
98
|
|
99
|
-
def file_size_mb
|
99
|
+
def file_size_mb
|
100
100
|
|
101
|
-
"#{((self.file_size >> 10).to_f / 1024).round(2)} Mb" if self.file_size
|
101
|
+
"#{((self.file_size >> 10).to_f / 1024).round(2)} Mb" if self.file_size
|
102
102
|
|
103
103
|
end
|
104
104
|
|
@@ -113,7 +113,7 @@ module Fclay
|
|
113
113
|
remote_file_url(style)
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def final_file_url(style=nil)
|
118
118
|
return self.file_name if self.file_location == "external_link"
|
119
119
|
if Fclay.configuration.storage_policy != :local
|
@@ -134,7 +134,7 @@ module Fclay
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def local_file_url(style=nil)
|
137
|
-
url = Fclay.configuration.local_storage_host
|
137
|
+
url = Fclay.configuration.local_storage_host
|
138
138
|
url += "#{Fclay.configuration.local_url}/#{self.class.name.tableize}"
|
139
139
|
url += "/#{style.to_s}" if style
|
140
140
|
url += "/#{file_name}"
|
@@ -142,12 +142,12 @@ module Fclay
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def short_local_file_url(style=nil)
|
145
|
-
|
145
|
+
|
146
146
|
end
|
147
147
|
|
148
|
-
def local_file_dir(style=nil)
|
148
|
+
def local_file_dir(style=nil)
|
149
149
|
dir = "#{Rails.root.to_s + Fclay.configuration.local_folder}/#{self.class.name.tableize}"
|
150
|
-
dir += "/#{style.to_s}" if style
|
150
|
+
dir += "/#{style.to_s}" if style
|
151
151
|
dir
|
152
152
|
end
|
153
153
|
|
@@ -156,10 +156,10 @@ module Fclay
|
|
156
156
|
path += "#{self.class.name.tableize}"
|
157
157
|
path += "/#{style.to_s}" if style
|
158
158
|
path += "/#{file_name}"
|
159
|
-
path
|
159
|
+
path
|
160
160
|
end
|
161
161
|
|
162
|
-
def delete_tmp_file
|
162
|
+
def delete_tmp_file
|
163
163
|
FileUtils.rm(@file.try(:path) || @file[:path],{:force => true}) if @file
|
164
164
|
@file = nil
|
165
165
|
end
|
@@ -173,58 +173,58 @@ module Fclay
|
|
173
173
|
end
|
174
174
|
|
175
175
|
def process_file
|
176
|
-
self.try(:log,"process_file called")
|
177
|
-
self.try(:log,"@file: #{@file.try(:to_s)}")
|
176
|
+
self.try(:log,"process_file called")
|
177
|
+
self.try(:log,"@file: #{@file.try(:to_s)}")
|
178
178
|
return unless @file
|
179
|
-
|
179
|
+
|
180
180
|
delete_files
|
181
181
|
path = @file.try(:path) || @file.try(:[],:path)
|
182
|
-
|
183
|
-
self.try(:log,"fetched path: #{path.try(:to_s)}")
|
182
|
+
|
183
|
+
self.try(:log,"fetched path: #{path.try(:to_s)}")
|
184
184
|
return unless path
|
185
|
-
|
185
|
+
|
186
186
|
self.content_type = @file.try(:content_type) || @file.try(:[],:content_type) if self.respond_to?(:'content_type=')
|
187
|
-
|
187
|
+
|
188
188
|
if path[0..3] == "http"
|
189
189
|
self.file_status = 'idle'
|
190
190
|
self.file_location = 'external_link'
|
191
191
|
self.file_name = path
|
192
|
-
else
|
192
|
+
else
|
193
193
|
create_dirs
|
194
194
|
fetch_file_name
|
195
195
|
|
196
|
-
(self.class.fclay_options[:styles] || [nil]).each do |style|
|
196
|
+
(self.class.fclay_options[:styles] || [nil]).each do |style|
|
197
197
|
FileUtils.cp(path,local_file_path(style))
|
198
198
|
`chmod 777 #{local_file_path(style)}`
|
199
199
|
end
|
200
|
-
|
200
|
+
self.original_file_name = @file.try(:original_filename) || @file.try(:[],:content_type)
|
201
201
|
delete_tmp_file
|
202
202
|
set_file_size self.class.fclay_options[:styles].try(:first)
|
203
203
|
self.file_location = 'local'
|
204
204
|
self.file_status = need_upload ? "processing" : "idle"
|
205
|
-
self.try(:log,"file_processed, file_status: #{self.file_status}")
|
205
|
+
self.try(:log,"file_processed, file_status: #{self.file_status}")
|
206
206
|
end
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
def fetch_file_name
|
210
|
-
|
210
|
+
|
211
211
|
return if self.file_name.present?
|
212
212
|
ext = fetch_extension
|
213
213
|
|
214
214
|
self.file_name = try(:fclay_attachment_filename)
|
215
215
|
self.file_name = SecureRandom.hex unless self.file_name
|
216
216
|
self.file_name += ".#{ext}" if ext
|
217
|
-
|
217
|
+
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def fetch_extension
|
221
221
|
ext = self.class.fclay_options[:extension]
|
222
222
|
return nil if ext == false
|
223
|
-
return ext.to_s if ext
|
223
|
+
return ext.to_s if ext
|
224
224
|
@file.original_filename.split(".").try(:last) if @file.try(:original_filename)
|
225
225
|
end
|
226
226
|
|
227
|
-
def delete_local_files
|
227
|
+
def delete_local_files
|
228
228
|
|
229
229
|
begin
|
230
230
|
(self.class.fclay_options[:styles] || [nil]).each do |style|
|
@@ -234,32 +234,31 @@ module Fclay
|
|
234
234
|
Rails.logger.info "Deleting Media #{id} sync file not found"
|
235
235
|
end
|
236
236
|
true
|
237
|
-
|
238
|
-
end
|
237
|
+
|
238
|
+
end
|
239
239
|
|
240
240
|
def delete_remote_files
|
241
|
-
|
241
|
+
|
242
242
|
(self.class.fclay_options[:styles] || [nil]).each do |style|
|
243
243
|
Fclay.remote_storage.bucket_object.object(remote_file_path(style)).delete
|
244
244
|
end
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
247
|
def set_file_size style=nil
|
248
248
|
self.file_size = File.size local_file_path(style)
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
def self.resolve_file_url navigation_complex_id,type,file_name,style=nil
|
252
|
-
|
252
|
+
|
253
253
|
return "" if file_name.nil? || type.nil?
|
254
|
-
|
254
|
+
|
255
255
|
path = "http://s3.amazonaws.com/#{Fclay.remote_storage.bucket_name}"
|
256
256
|
path += "/navigation_complex/#{navigation_complex_id}" if navigation_complex_id
|
257
257
|
path += "/#{type}"
|
258
258
|
path += "/#{style.to_s}" if style
|
259
259
|
path += "/#{file_name}"
|
260
260
|
path
|
261
|
-
end
|
261
|
+
end
|
262
262
|
|
263
263
|
end
|
264
264
|
end
|
265
|
-
|
data/lib/fclay/version.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
|
-
|
3
|
+
|
4
4
|
add_column :<%= table_name %>, :file_name, :string
|
5
|
+
add_column :<%= table_name %>, :original_file_name, :string
|
5
6
|
add_column :<%= table_name %>, :file_size, :integer
|
6
7
|
add_column :<%= table_name %>, :file_status, :string, :default => "new"
|
7
8
|
add_column :<%= table_name %>, :file_location, :string
|
8
9
|
add_column :<%= table_name %>, :content_type, :string
|
9
|
-
|
10
|
+
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
|
13
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fclay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.46
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Galiev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.6.
|
102
|
+
rubygems_version: 2.6.13
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Summary
|