|
|
|
@ -469,37 +469,43 @@ class ShixunsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 实训测试集附件
|
|
|
|
|
def upload_data_sets
|
|
|
|
|
upload_file = params["file"]
|
|
|
|
|
raise "未上传文件" unless upload_file
|
|
|
|
|
folder = edu_setting('shixun_folder')
|
|
|
|
|
raise "存储目录未定义" unless folder.present?
|
|
|
|
|
rep_name = @shixun.data_sets.pluck(:filename).include?(upload_file.original_filename)
|
|
|
|
|
raise "文件名已经存在\"#{upload_file.original_filename}\", 请删除后再上传" if rep_name
|
|
|
|
|
tpm_folder = params[:identifier] # 这个是实训的identifier
|
|
|
|
|
save_path = File.join(folder, tpm_folder)
|
|
|
|
|
ext = file_ext(upload_file.original_filename)
|
|
|
|
|
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
|
|
|
|
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
|
|
|
|
disk_filename = local_path[save_path.size + 1, local_path.size]
|
|
|
|
|
@attachment = Attachment.where(disk_filename: disk_filename,
|
|
|
|
|
author_id: current_user.id).first
|
|
|
|
|
if @attachment.blank?
|
|
|
|
|
@attachment = Attachment.new
|
|
|
|
|
@attachment.filename = upload_file.original_filename
|
|
|
|
|
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
|
|
|
|
@attachment.filesize = upload_file.tempfile.size
|
|
|
|
|
@attachment.content_type = content_type
|
|
|
|
|
@attachment.digest = digest
|
|
|
|
|
@attachment.author_id = current_user.id
|
|
|
|
|
@attachment.disk_directory = tpm_folder
|
|
|
|
|
@attachment.container_id = @shixun.id
|
|
|
|
|
@attachment.container_type = @shixun.class.name
|
|
|
|
|
@attachment.attachtype = 2
|
|
|
|
|
@attachment.save!
|
|
|
|
|
else
|
|
|
|
|
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
upload_file = params["file"]
|
|
|
|
|
raise "未上传文件" unless upload_file
|
|
|
|
|
folder = edu_setting('shixun_folder')
|
|
|
|
|
raise "存储目录未定义" unless folder.present?
|
|
|
|
|
rep_name = @shixun.data_sets.pluck(:filename).include?(upload_file.original_filename)
|
|
|
|
|
raise "文件名已经存在\"#{upload_file.original_filename}\", 请删除后再上传" if rep_name
|
|
|
|
|
tpm_folder = params[:identifier] # 这个是实训的identifier
|
|
|
|
|
save_path = File.join(folder, tpm_folder)
|
|
|
|
|
ext = file_ext(upload_file.original_filename)
|
|
|
|
|
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
|
|
|
|
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
|
|
|
|
disk_filename = local_path[save_path.size + 1, local_path.size]
|
|
|
|
|
@attachment = Attachment.where(disk_filename: disk_filename,
|
|
|
|
|
author_id: current_user.id).first
|
|
|
|
|
if @attachment.blank?
|
|
|
|
|
@attachment = Attachment.new
|
|
|
|
|
@attachment.filename = upload_file.original_filename
|
|
|
|
|
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
|
|
|
|
@attachment.filesize = upload_file.tempfile.size
|
|
|
|
|
@attachment.content_type = content_type
|
|
|
|
|
@attachment.digest = digest
|
|
|
|
|
@attachment.author_id = current_user.id
|
|
|
|
|
@attachment.disk_directory = tpm_folder
|
|
|
|
|
@attachment.container_id = @shixun.id
|
|
|
|
|
@attachment.container_type = @shixun.class.name
|
|
|
|
|
@attachment.attachtype = 2
|
|
|
|
|
@attachment.save!
|
|
|
|
|
else
|
|
|
|
|
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
|
|
|
|
end
|
|
|
|
|
render_ok
|
|
|
|
|
rescue => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
end
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 多文件删除
|
|
|
|
|