From acc323e46df6aa156e077f9e13519995945804f5 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 30 May 2016 18:35:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?issue7890=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 386e5733d..1ce834f61 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -10,14 +10,14 @@ class ZipdownController < ApplicationController #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" + MAX_PATH = 250 #统一下载功能 def download if User.current.logged? begin if params[:base64file] - file = Base64.decode64(params[:base64file]) - file = file.sub('*', '+') + file = decode64(params[:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file) else send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file]) @@ -125,7 +125,11 @@ class ZipdownController < ApplicationController end def encode64(str) - Base64.encode64(str).sub('+', '*') + Base64.urlsafe_encode64(str) + end + + def decode64(str) + Base64.urlsafe_decode64(str) end def zip_homework_common homework_common @@ -242,6 +246,12 @@ class ZipdownController < ApplicationController def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" + # 文件名过长 + + if rename_zipfile.size > MAX_PATH + rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4] + end + zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) From 858ad47338e1b9d16dcf981f9c8eeb736c4121a4 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 30 May 2016 18:40:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E5=AE=9A=E4=B8=BA50?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 1ce834f61..d9a9e1def 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -10,7 +10,7 @@ class ZipdownController < ApplicationController #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" - MAX_PATH = 250 + MAX_PATH = 50 #统一下载功能 def download