This commit is contained in:
parent
7d10a5ce66
commit
9645d6f0c0
|
@ -33,8 +33,6 @@ class ZipdownController < ApplicationController
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
render file: 'public/no_file_found.html' , :layout => 'course_base'
|
render file: 'public/no_file_found.html' , :layout => 'course_base'
|
||||||
#logger.error "[ZipDown] ===> #{e}"
|
|
||||||
#@error = e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#下载某一学生的作业的所有文件
|
#下载某一学生的作业的所有文件
|
||||||
|
@ -69,7 +67,6 @@ class ZipdownController < ApplicationController
|
||||||
user_zip_paths = homeattaches.map do |homeattach|
|
user_zip_paths = homeattaches.map do |homeattach|
|
||||||
zip_homework_by_user homeattach
|
zip_homework_by_user homeattach
|
||||||
end
|
end
|
||||||
#zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
|
||||||
user_zip_paths
|
user_zip_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,32 +84,17 @@ class ZipdownController < ApplicationController
|
||||||
#has_file = true unless has_file
|
#has_file = true unless has_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#unless has_file
|
|
||||||
# render file: 'public/no_file_fond.html' , :layout => 'course_base'
|
|
||||||
#end
|
|
||||||
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
||||||
|
|
||||||
#@paths = homeworks_attach_path
|
|
||||||
#zipfile = ziping homeworks_attach_path
|
|
||||||
#send_file zipfile, :filename => bid.name,
|
|
||||||
# :type => detect_content_type(zipfile)
|
|
||||||
#rescue Errno::ENOENT => e
|
|
||||||
# logger.error "[Errno::ENOENT] ===> #{e}"
|
|
||||||
# @error = e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def zip_homework_by_user(homeattach)
|
def zip_homework_by_user(homeattach)
|
||||||
#if homeattach.attachments.count > 0
|
|
||||||
homeworks_attach_path = []
|
homeworks_attach_path = []
|
||||||
# 需要将所有homework.attachments遍历加入zip
|
# 需要将所有homework.attachments遍历加入zip
|
||||||
# 并且返回zip路径
|
# 并且返回zip路径
|
||||||
user_attaches_paths = homeattach.attachments.each do |attach|
|
user_attaches_paths = homeattach.attachments.each do |attach|
|
||||||
#length = attach.storage_path.length
|
|
||||||
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
||||||
end
|
end
|
||||||
zipping("#{homework.user.user_extensions.student_id}_#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
zipping("#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
||||||
#user_attaches_paths
|
|
||||||
#end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,28 +124,6 @@ class ZipdownController < ApplicationController
|
||||||
logger.error "[zipdown#zipping] ===> #{e}"
|
logger.error "[zipdown#zipping] ===> #{e}"
|
||||||
@error = e
|
@error = e
|
||||||
end
|
end
|
||||||
|
|
||||||
#def ziping files_path
|
|
||||||
# ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
|
|
||||||
# folder = SaveFolder
|
|
||||||
# input_filename = files_path
|
|
||||||
# zipfile_name = "#{OutputFolder}/archive_#{Time.now.to_i}.zip"
|
|
||||||
#
|
|
||||||
# Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
|
||||||
# Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
||||||
# input_filename.each do |filename|
|
|
||||||
# zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
|
|
||||||
# end
|
|
||||||
# zipfile.get_output_stream("ReadMe") { |os|
|
|
||||||
# os.write "Homeworks"
|
|
||||||
# }
|
|
||||||
# end
|
|
||||||
# zipfile_name
|
|
||||||
#rescue Errno => e
|
|
||||||
# logger.error "[zipdown#zipping] ===> #{e}"
|
|
||||||
# @error = e
|
|
||||||
#end
|
|
||||||
|
|
||||||
def detect_content_type(name)
|
def detect_content_type(name)
|
||||||
content_type = Redmine::MimeType.of(name)
|
content_type = Redmine::MimeType.of(name)
|
||||||
content_type.to_s
|
content_type.to_s
|
||||||
|
@ -173,5 +133,4 @@ class ZipdownController < ApplicationController
|
||||||
attach = Attachment.find_by_disk_filename(name)
|
attach = Attachment.find_by_disk_filename(name)
|
||||||
attach.filename
|
attach.filename
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue