|
|
@ -10,14 +10,14 @@ class ZipdownController < ApplicationController
|
|
|
|
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
|
|
|
|
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
|
|
|
|
SAVE_FOLDER = "#{Rails.root}/files"
|
|
|
|
SAVE_FOLDER = "#{Rails.root}/files"
|
|
|
|
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
|
|
|
|
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
|
|
|
|
|
|
|
|
MAX_PATH = 250
|
|
|
|
|
|
|
|
|
|
|
|
#统一下载功能
|
|
|
|
#统一下载功能
|
|
|
|
def download
|
|
|
|
def download
|
|
|
|
if User.current.logged?
|
|
|
|
if User.current.logged?
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
if params[:base64file]
|
|
|
|
if params[:base64file]
|
|
|
|
file = Base64.decode64(params[:base64file])
|
|
|
|
file = decode64(params[:base64file])
|
|
|
|
file = file.sub('*', '+')
|
|
|
|
|
|
|
|
send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file)
|
|
|
|
send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def encode64(str)
|
|
|
|
def encode64(str)
|
|
|
|
Base64.encode64(str).sub('+', '*')
|
|
|
|
Base64.urlsafe_encode64(str)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decode64(str)
|
|
|
|
|
|
|
|
Base64.urlsafe_decode64(str)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def zip_homework_common homework_common
|
|
|
|
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=[])
|
|
|
|
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"
|
|
|
|
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}"
|
|
|
|
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
|
|
|
|
|
|
|
|
|
|
|
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
|
|
|
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
|
|
|