This commit is contained in:
chiu 2019-10-23 13:54:31 +08:00
parent c56cfab46d
commit d6da2bb587
2 changed files with 25 additions and 23 deletions

View File

@ -345,52 +345,47 @@ class Admin::GalleriesController < OrbitAdminController
def upload_process def upload_process
if @@upload_success == true if $upload_success == true
count = @@image_unprocessed.length count = AlbumUnprocess.all.count
Thread.new do Thread.new do
begin begin
@@start = true @@start = true
@@image_unprocessed.each_with_index do |image,i| album_unprocess = AlbumUnprocess.all
@@progress_filename = @@file[i].original_filename album_unprocess.each_with_index do |image,i|
image.file = @@file[i] @@progress_filename = image.file.original_filename
image.save! album = AlbumImage.where(id: image.album_id)
album.file = image.file
album.save!
@@progress_percent = ((i+1)*100.0/count).floor.to_s + '%' @@progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
end end
AlbumUnprocess.delete_all
rescue => e rescue => e
puts e.inspect puts e.inspect
end end
@@file = [] $upload_success = false
@@image_unprocessed = []
@upload_success = false
@@finish = true @@finish = true
end end
end end
end end
def start_upload_process def start_upload_process
@@upload_success = true $upload_success = true
sleep 0.01
render :json => {}.to_json render :json => {}.to_json
end end
def init_upload def init_upload
@@image_unprocessed = []
@@start = false @@start = false
@@finish = false @@finish = false
@@file = []
@@progress_percent = '0%' @@progress_percent = '0%'
@@progress_filename = 'processing!!' @@progress_filename = 'processing!!'
render :json => {}.to_json render :json => {}.to_json
end end
def upload_image def upload_image
sleep 0.01
if !(@@image_unprocessed.nil?)
album = Album.find(params[:album_id]) album = Album.find(params[:album_id])
files = params['files'] files = params['files']
files.each do |file| files.each do |file|
image = album.album_images.new image = album.album_images.new
@@file << file
image.tags = (album.tags rescue []) image.tags = (album.tags rescue [])
@@image_unprocessed << image AlbumUnprocess.create(album_id:image.id,file:file)
end image.save!
end end
render :json=>{"files"=>[{}]}.to_json render :json=>{"files"=>[{}]}.to_json
end end

View File

@ -0,0 +1,7 @@
class AlbumUnprocess
include Mongoid::Document
include Mongoid::Timestamps
field :album_id
field :file
end