|
|
@ -29,26 +29,25 @@ class ZipdownController < ApplicationController
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif params[:obj_class] == "HomeworkCommon"
|
|
|
|
|
|
|
|
homework = HomeworkCommon.find params[:obj_id]
|
|
|
|
|
|
|
|
render_403 if User.current.allowed_to?(:as_teacher,homework.course)
|
|
|
|
|
|
|
|
file_count = 0
|
|
|
|
|
|
|
|
homework.student_works.map { |work| file_count += work.attachments.count}
|
|
|
|
|
|
|
|
if file_count > 0
|
|
|
|
|
|
|
|
zipfile = zip_homework_common homework
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
|
|
|
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
|
|
|
end
|
|
|
|
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|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json {
|
|
|
|
format.json {
|
|
|
|
render json: zipfile.to_json
|
|
|
|
render json: zipfile.to_json
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#rescue Exception => e
|
|
|
|
|
|
|
|
# render file: 'public/no_file_found.html'
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#下载某一学生的作业的所有文件
|
|
|
|
#下载某一学生的作业的所有文件
|
|
|
@ -98,29 +97,34 @@ class ZipdownController < ApplicationController
|
|
|
|
digests << out_file.file_digest
|
|
|
|
digests << out_file.file_digest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
homework_id = bid.id
|
|
|
|
homework_id = bid.id
|
|
|
|
user_id = bid.author_id
|
|
|
|
user_id = bid.author_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out_file = find_or_pack(homework_id, user_id, digests.sort){
|
|
|
|
out_file = find_or_pack(homework_id, user_id, digests.sort){
|
|
|
|
zipping("#{Time.now.to_i}_#{bid.name}.zip",
|
|
|
|
zipping("#{Time.now.to_i}_#{bid.name}.zip",
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
|
|
|
|
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
|
|
|
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def zip_homework_common homework_common
|
|
|
|
# zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024)
|
|
|
|
bid_homework_path = []
|
|
|
|
# x = 0
|
|
|
|
digests = []
|
|
|
|
#
|
|
|
|
homework_common.student_works.each do |work|
|
|
|
|
#
|
|
|
|
unless work.attachments.empty?
|
|
|
|
# zips.each { |o|
|
|
|
|
out_file = zip_student_work_by_user(work)
|
|
|
|
# x += 1
|
|
|
|
bid_homework_path << out_file.file_path
|
|
|
|
# file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER
|
|
|
|
digests << out_file.file_digest
|
|
|
|
# o[:real_file] = file
|
|
|
|
end
|
|
|
|
# o[:file] = File.basename(file)
|
|
|
|
end
|
|
|
|
# o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2)
|
|
|
|
homework_id = homework_common.id
|
|
|
|
# }
|
|
|
|
user_id = homework_common.user_id
|
|
|
|
|
|
|
|
out_file = find_or_pack(homework_id, user_id, digests.sort){
|
|
|
|
|
|
|
|
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
|
|
|
|
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
|
|
|
|
}
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
|
|
|
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
@ -131,8 +135,6 @@ class ZipdownController < ApplicationController
|
|
|
|
homeworks_attach_path = []
|
|
|
|
homeworks_attach_path = []
|
|
|
|
not_exist_file = []
|
|
|
|
not_exist_file = []
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
digests = []
|
|
|
|
digests = []
|
|
|
|
homework_attach.attachments.each do |attach|
|
|
|
|
homework_attach.attachments.each do |attach|
|
|
|
|
if File.exist?(attach.diskfile)
|
|
|
|
if File.exist?(attach.diskfile)
|
|
|
@ -143,12 +145,30 @@ class ZipdownController < ApplicationController
|
|
|
|
digests << 'not_exist_file'
|
|
|
|
digests << 'not_exist_file'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){
|
|
|
|
out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){
|
|
|
|
zipping("#{homework_attach.user.lastname}#{homework_attach.user.firstname}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
|
|
|
zipping("#{homework_attach.user.lastname}#{homework_attach.user.firstname}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
|
|
|
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
|
|
|
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def zip_student_work_by_user work
|
|
|
|
|
|
|
|
homeworks_attach_path = []
|
|
|
|
|
|
|
|
not_exist_file = []
|
|
|
|
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
|
|
|
|
digests = []
|
|
|
|
|
|
|
|
work.attachments.each do |attach|
|
|
|
|
|
|
|
|
if File.exist?(attach.diskfile)
|
|
|
|
|
|
|
|
homeworks_attach_path << attach.diskfile
|
|
|
|
|
|
|
|
digests << attach.digest
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
not_exist_file << attach.filename
|
|
|
|
|
|
|
|
digests << 'not_exist_file'
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
|
|
|
|
|
|
|
|
zipping("#{work.user.lastname}#{work.user.firstname}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
|
|
|
|
|
|
|
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
|
|
|
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|