@ -7,17 +7,6 @@ class ZipdownController < ApplicationController
SAVE_FOLDER = " #{ Rails . root } /files "
OUTPUT_FOLDER = " #{ Rails . root } /tmp/archiveZip "
#通过作业Id找到项目( 课程)
def find_project_by_bid_id
obj_class = params [ :obj_class ]
obj_id = params [ :obj_id ]
obj = obj_class . constantize . find ( obj_id )
case obj . class . to_s . to_sym
when :Bid
@project = obj . courses [ 0 ]
end
end
def assort
if params [ :obj_class ] == " Bid "
bid = Bid . find params [ :obj_id ]
@ -33,8 +22,8 @@ class ZipdownController < ApplicationController
end
send_file zipfile , :filename = > bid . name + " .zip " , :type = > detect_content_type ( zipfile ) if zipfile
rescue Exception = > e
render file : 'public/no_file_found.html'
#rescue Exception => e
# render file: 'public/no_file_found.html'
end
#下载某一学生的作业的所有文件
@ -56,12 +45,23 @@ class ZipdownController < ApplicationController
else
render_403
end
rescue = > e
render file : 'public/file_not_found.html'
#rescue => e
# render file: 'public/file_not_found.html'
end
private
#通过作业Id找到项目( 课程)
def find_project_by_bid_id
obj_class = params [ :obj_class ]
obj_id = params [ :obj_id ]
obj = obj_class . constantize . find ( obj_id )
case obj . class . to_s . to_sym
when :Bid
@project = obj . courses [ 0 ]
end
end
def zip_bid ( bid )
# Todo: User Access Controll
bid_homework_path = [ ]
@ -101,10 +101,20 @@ class ZipdownController < ApplicationController
Zip :: File . open ( zipfile_name , Zip :: File :: CREATE ) do | zipfile |
input_filename . each do | filename |
flag = true
index = 1
rename_file = ic . iconv ( ( File . basename ( filename ) ) ) . to_s
rename_file = ic . iconv ( filename_to_real ( File . basename ( filename ) ) ) . to_s if is_attachment
zipfile . add ( rename_file , filename )
begin
zipfile . add ( rename_file , filename )
flag = false
rescue Exception = > e
zipfile . get_output_stream ( 'FILE_NOTICE.txt' ) do | os |
os . write l ( :label_file_exist )
end
next
end
end
unless not_exist_file . empty?
zipfile . get_output_stream ( 'FILE_LOST.txt' ) do | os |
@ -113,9 +123,9 @@ class ZipdownController < ApplicationController
end
end
zipfile_name
rescue Errno = > e
logger . error " [zipdown # zipping] ===> #{ e } "
@error = e
#rescue Errno => e
# logger.error "[zipdown#zipping] ===> #{e}"
# @error = e
end
def detect_content_type ( name )
content_type = Redmine :: MimeType . of ( name )