fix recreate thumb problem
This commit is contained in:
parent
86aacba3b6
commit
8577c7e8ad
|
@ -40,19 +40,20 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3])
|
||||
end
|
||||
end
|
||||
@@finish = false
|
||||
@@start = false
|
||||
variable = AlbumVariable.first
|
||||
variable.finish = false
|
||||
variable.save!
|
||||
Thread.new do
|
||||
@@start = true
|
||||
variable = AlbumVariable.first
|
||||
images.each_with_index do |image,index|
|
||||
@@progress_percent = (index*100.0/count).floor.to_s+'%'
|
||||
variable.progress_percent = (index*100.0/count).floor.to_s+'%'
|
||||
all_version = image.file.versions.map{|k,v| k}
|
||||
begin
|
||||
#org_fname = image.file.path
|
||||
#org_extname = File.extname(org_fname)
|
||||
#org_fname.slice! org_extname
|
||||
#FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname)
|
||||
@@progress_filename = image[:file].to_s
|
||||
variable.progress_filename = image[:file].to_s
|
||||
all_version.each do |version|
|
||||
if !(version.to_s == 'resized' && crop_but_no_backup(image))
|
||||
image.file.recreate_versions! version
|
||||
|
@ -60,11 +61,13 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
end
|
||||
end
|
||||
rescue => e
|
||||
@@progress_filename = e.inspect.to_s
|
||||
variable.progress_filename = e.inspect.to_s
|
||||
puts e.inspect
|
||||
end
|
||||
variable.save!
|
||||
end
|
||||
@@finish = true
|
||||
variable.finish = true
|
||||
variable.save!
|
||||
end
|
||||
rescue => e
|
||||
puts e.inspect
|
||||
|
@ -77,9 +80,12 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
render :json => {'translate' => "#{t(text.to_s)}" }.to_json
|
||||
end
|
||||
def recreate_image
|
||||
notalive = @@progress_percent.nil? rescue true
|
||||
notalive = ((AlbumVariable.first.notalive.nil? ? true : AlbumVariable.first.notalive) rescue true)
|
||||
if notalive
|
||||
if !params['album_id'].to_s.empty?
|
||||
variable = AlbumVariable.first
|
||||
variable.finish = false
|
||||
variable.save!
|
||||
choice_ids = params['album_id'].split(',')
|
||||
albums = Album.all.select { |value| (choice_ids.include? value.id.to_s)}
|
||||
if !(params['use_default']=='true')
|
||||
|
@ -92,12 +98,9 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
end
|
||||
end
|
||||
end
|
||||
@@start = false
|
||||
count = 0
|
||||
albums.each{|album| count+=album.album_images.count }
|
||||
@@finish = false
|
||||
Thread.new do
|
||||
@@start = true
|
||||
i = 0
|
||||
albums.each do |album|
|
||||
album.album_images.each do |image|
|
||||
|
@ -112,42 +115,44 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
end
|
||||
rescue => error
|
||||
end
|
||||
@@progress_percent = (i*100.0/count).floor.to_s+'%'
|
||||
variable = AlbumVariable.first
|
||||
variable.progress_percent = (i*100.0/count).floor.to_s+'%'
|
||||
if !error.nil?
|
||||
@@progress_filename = error.inspect.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
|
||||
variable.progress_filename = error.inspect.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
|
||||
sleep(1)
|
||||
else
|
||||
@@progress_filename = image[:file].to_s
|
||||
variable.progress_filename = image[:file].to_s
|
||||
end
|
||||
variable.save!
|
||||
i+=1
|
||||
end
|
||||
end
|
||||
@@finish = true
|
||||
variable = AlbumVariable.first
|
||||
variable.finish = true
|
||||
variable.save!
|
||||
end
|
||||
else
|
||||
@@start = true
|
||||
@@progress_filename = ''
|
||||
@@finish = true
|
||||
@@progress_percent = '100%'
|
||||
variable = AlbumVariable.first
|
||||
variable.finish = true
|
||||
variable.progress_filename = ''
|
||||
variable.progress_percent = '100%'
|
||||
variable.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
def finish_recreate
|
||||
@@progress_percent = nil
|
||||
@@progress_filename = nil
|
||||
@@start = false
|
||||
variable = AlbumVariable.first
|
||||
variable.progress_percent = '0%'
|
||||
variable.progress_filename = ''
|
||||
variable.notalive = true
|
||||
variable.save!
|
||||
render :text => ''
|
||||
end
|
||||
def recreate_progress
|
||||
if self.class.class_variable_defined? :@@start
|
||||
if @@start
|
||||
render :json => {'percent' => (@@progress_percent rescue '0%'), 'filename' => (@@progress_filename rescue ''), 'finish' => (@@finish rescue false) }.to_json
|
||||
else
|
||||
render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json
|
||||
end
|
||||
else
|
||||
render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json
|
||||
end
|
||||
progress_percent = AlbumVariable.first.progress_percent rescue '0%'
|
||||
progress_filename = AlbumVariable.first.progress_filename rescue ''
|
||||
finish = AlbumVariable.first.finish rescue false
|
||||
render :json => {'percent' => progress_percent, 'filename' => progress_filename, 'finish' => finish }.to_json
|
||||
end
|
||||
def index
|
||||
Album.each do |album|
|
||||
|
@ -353,8 +358,7 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
album_unprocess = AlbumUnprocess.all
|
||||
count = album_unprocess.count
|
||||
Thread.new do
|
||||
begin
|
||||
@@start = true
|
||||
begin
|
||||
album_unprocess.each_with_index do |un_image,i|
|
||||
album = AlbumImage.all.select{|value| value.id.to_s == un_image.image_id.to_s}[0]
|
||||
album.file = un_image.save_var
|
||||
|
@ -363,13 +367,17 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
file.close
|
||||
File.delete file.path
|
||||
un_image.delete
|
||||
@@progress_filename = album[:file]
|
||||
@@progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
|
||||
variable = AlbumVariable.first
|
||||
variable.progress_filename = album[:file]
|
||||
variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
|
||||
variable.save!
|
||||
end
|
||||
rescue => e
|
||||
puts ['err',e.inspect]
|
||||
end
|
||||
@@finish = true
|
||||
variable = AlbumVariable.first
|
||||
variable.finish = true
|
||||
variable.save!
|
||||
end
|
||||
album_temp = AlbumUnprocess.first
|
||||
album_temp.upload_success = false
|
||||
|
@ -383,11 +391,13 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
render :json => {}.to_json
|
||||
end
|
||||
def init_upload
|
||||
Thread.current['count'] = params['all_length'].to_i
|
||||
@@start = false
|
||||
@@finish = false
|
||||
@@progress_percent = '0%'
|
||||
@@progress_filename = 'processing!!'
|
||||
variable = AlbumVariable.first
|
||||
variable.count = params['all_length'].to_i
|
||||
variable.finish = false
|
||||
variable.progress_percent = '0%'
|
||||
variable.progress_filename = 'processing!!'
|
||||
variable.notalive = true
|
||||
variable.save!
|
||||
render :json => {}.to_json
|
||||
end
|
||||
def upload_image
|
||||
|
@ -397,7 +407,7 @@ class Admin::GalleriesController < OrbitAdminController
|
|||
files.each do |file|
|
||||
image = album.album_images.new
|
||||
image.tags = (album.tags rescue [])
|
||||
if Thread.current['count']==1
|
||||
if AlbumVariable.first.count==1
|
||||
image.file = file
|
||||
else
|
||||
album_unprocess.image_id = image.id
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class AlbumVariable
|
||||
include Mongoid::Document
|
||||
field :count, type: Integer
|
||||
field :progress_percent, type: String
|
||||
field :progress_filename, type: String
|
||||
field :finish, type: Boolean
|
||||
field :notalive, type: Boolean
|
||||
end
|
|
@ -35,5 +35,5 @@ function get_data(){
|
|||
}
|
||||
})
|
||||
}
|
||||
var id = setInterval(get_data,200)
|
||||
var id = setInterval(get_data,1000)
|
||||
</SCRIPT>
|
|
@ -35,5 +35,5 @@ function get_data(){
|
|||
}
|
||||
})
|
||||
}
|
||||
var id = setInterval(get_data,200)
|
||||
var id = setInterval(get_data,1000)
|
||||
</SCRIPT>
|
Loading…
Reference in New Issue