|
|
|
@ -458,12 +458,66 @@ class ShixunsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Jupyter数据集
|
|
|
|
|
def jupyter_data_sets
|
|
|
|
|
def get_data_sets
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
limit = params[:limit] || 10
|
|
|
|
|
data_sets = @shixun.jupyter_data_sets
|
|
|
|
|
data_sets = @shixun.data_sets
|
|
|
|
|
@data_count = data_sets.count
|
|
|
|
|
@data_sets= data_sets.page(page).per(limit)
|
|
|
|
|
@absolute_folder = edu_setting('shixun_folder')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 实训测试集附件
|
|
|
|
|
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.cloud_url = remote_path
|
|
|
|
|
@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
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 多文件删除
|
|
|
|
|
def destroy_data_sets
|
|
|
|
|
files = Attachment.where(id: params[:id])
|
|
|
|
|
shixun_folder= edu_setting("shixun_folder")
|
|
|
|
|
begin
|
|
|
|
|
files.each do |file|
|
|
|
|
|
file_path = "#{shixun_folder}/#{file.relative_path_filename}"
|
|
|
|
|
delete_file(file_path)
|
|
|
|
|
end
|
|
|
|
|
files.destroy_all
|
|
|
|
|
render_ok
|
|
|
|
|
rescue => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def apply_shixun_mirror
|
|
|
|
@ -1020,4 +1074,26 @@ private
|
|
|
|
|
ShixunSecretRepository.create!(repo_name: repo_path.split(".")[0], shixun_id: @shixun.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def file_save_to_local(save_path, temp_file, ext)
|
|
|
|
|
unless Dir.exists?(save_path)
|
|
|
|
|
FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
digest = md5_file(temp_file)
|
|
|
|
|
digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
|
|
|
|
|
local_file_path = File.join(save_path, digest) + ext
|
|
|
|
|
save_temp_file(temp_file, local_file_path)
|
|
|
|
|
|
|
|
|
|
[local_file_path, digest]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def save_temp_file(temp_file, save_file_path)
|
|
|
|
|
File.open(save_file_path, 'wb') do |f|
|
|
|
|
|
temp_file.rewind
|
|
|
|
|
while (buffer = temp_file.read(8192))
|
|
|
|
|
f.write(buffer)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|