|
|
|
@ -25,17 +25,25 @@ class ZipdownController < ApplicationController
|
|
|
|
|
zipfile = zip_bid bid
|
|
|
|
|
else
|
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if zipfile
|
|
|
|
|
if zipfile.length > 1
|
|
|
|
|
@mut_down_files = zipfile.map{|x| File.basename(x)}
|
|
|
|
|
else
|
|
|
|
|
send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile)
|
|
|
|
|
end
|
|
|
|
|
# if zipfile
|
|
|
|
|
# if zipfile.length > 1
|
|
|
|
|
# @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)}
|
|
|
|
|
# else
|
|
|
|
|
# send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file])
|
|
|
|
|
# return
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.json {
|
|
|
|
|
render json: zipfile.to_json
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
#rescue Exception => e
|
|
|
|
|
# render file: 'public/no_file_found.html'
|
|
|
|
@ -86,13 +94,18 @@ class ZipdownController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i)
|
|
|
|
|
zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024)
|
|
|
|
|
x = 0
|
|
|
|
|
|
|
|
|
|
zips.map { |o|
|
|
|
|
|
|
|
|
|
|
zips.each { |o|
|
|
|
|
|
x += 1
|
|
|
|
|
zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o, OUTPUT_FOLDER
|
|
|
|
|
file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER
|
|
|
|
|
o[:real_file] = file
|
|
|
|
|
o[:file] = File.basename(file)
|
|
|
|
|
o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def zip_homework_by_user(homeattach)
|
|
|
|
@ -163,14 +176,14 @@ class ZipdownController < ApplicationController
|
|
|
|
|
max_size = 0
|
|
|
|
|
last_files = []
|
|
|
|
|
ret_files = []
|
|
|
|
|
files.each do |f|
|
|
|
|
|
files.each_with_index do |f,i|
|
|
|
|
|
if (max_size += File.size(f)) > pack_attachment_max_size
|
|
|
|
|
max_size = 0
|
|
|
|
|
if last_files.empty? #如果单个文件超过大小,也将此文件作为一组
|
|
|
|
|
ret_files << [f]
|
|
|
|
|
ret_files << {files: [f], count: 1, index: ret_files.count+1}
|
|
|
|
|
last_files.clear
|
|
|
|
|
else
|
|
|
|
|
ret_files << last_files
|
|
|
|
|
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1}
|
|
|
|
|
last_files.clear
|
|
|
|
|
redo
|
|
|
|
|
end
|
|
|
|
@ -179,7 +192,7 @@ class ZipdownController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ret_files << last_files unless last_files.empty?
|
|
|
|
|
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty?
|
|
|
|
|
ret_files
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|