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