From d6da2bb587a1ca98587998beb9497c8abee0bb82 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 23 Oct 2019 13:54:31 +0800 Subject: [PATCH] fix? --- app/controllers/admin/galleries_controller.rb | 41 ++++++++----------- app/models/album_unprocess.rb | 7 ++++ 2 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 app/models/album_unprocess.rb diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index b5d0a27..8548a22 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -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 diff --git a/app/models/album_unprocess.rb b/app/models/album_unprocess.rb new file mode 100644 index 0000000..d588346 --- /dev/null +++ b/app/models/album_unprocess.rb @@ -0,0 +1,7 @@ +class AlbumUnprocess + include Mongoid::Document + include Mongoid::Timestamps + + field :album_id + field :file +end \ No newline at end of file