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

View File

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