From d82207aa683ab32f95186f6311de2e3149b1ebca Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 28 Feb 2020 09:21:35 +0800 Subject: [PATCH] fix the problem that when upload failed if will lead to not upload success furthor more and let show description tag can also work for image --- app/controllers/admin/galleries_controller.rb | 47 ++++++++++--------- app/controllers/galleries_controller.rb | 2 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index b3b60fb..0948ed9 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -473,33 +473,34 @@ class Admin::GalleriesController < OrbitAdminController def upload_process if AlbumUnprocess.first.upload_success - album_unprocess = AlbumUnprocess.all - count = album_unprocess.count - Thread.new do - 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 - album.save! - file = un_image.save_var.tempfile - file.close - File.delete file.path - un_image.delete - variable = AlbumVariable.first + album_unprocess = Array(AlbumUnprocess.all) + count = album_unprocess.count + Thread.new do + album_unprocess.each_with_index do |un_image,i| + begin + album = AlbumImage.all.select{|value| value.id.to_s == un_image.image_id.to_s}[0] + album.file = un_image.save_var + album.save! + file = un_image.save_var.tempfile + file.close + File.delete file.path + un_image.delete + 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 - variable = AlbumVariable.first - variable.finish = true - variable.save! + rescue => e + puts ['err',un_image.inspect,e.inspect] + un_image.destroy + end end - album_temp = AlbumUnprocess.first - album_temp.upload_success = false - album_temp.save! + variable = AlbumVariable.first + variable.finish = true + variable.save! + end + album_temp = AlbumUnprocess.first + album_temp.upload_success = false + album_temp.save! end end def start_upload_process diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index bdafa4b..3108874 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -63,7 +63,7 @@ class GalleriesController < ApplicationController images = album.album_images.asc(:order).collect do |a| alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description) { - "image-description" => a.description, + "image-description" => (flag ? a.description : ''), "alt_title" => alt_text, "link_to_show" => "/xhr/galleries/theater/" + a.id.to_s, "thumb-src" => a.file.thumb.url