Merge branch 'dev_jupyter' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_jupyter

chromesetting
杨树林 5 years ago
commit 2c982d55f1

@ -28,52 +28,57 @@ class AttachmentsController < ApplicationController
def create def create
# 1. 本地存储 # 1. 本地存储
# 2. 上传到云 # 2. 上传到云
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 begin
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
raise "未上传文件" unless upload_file uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
raise "未上传文件" unless upload_file
folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present? folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present?
month_folder = current_month_folder
save_path = File.join(folder, month_folder) month_folder = current_month_folder
save_path = File.join(folder, month_folder)
ext = file_ext(upload_file.original_filename)
ext = file_ext(upload_file.original_filename)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
content_type = upload_file.content_type.presence || 'application/octet-stream'
content_type = upload_file.content_type.presence || 'application/octet-stream'
# remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端 # remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}" logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
disk_filename = local_path[save_path.size + 1, local_path.size]
#存数据库 disk_filename = local_path[save_path.size + 1, local_path.size]
# #存数据库
@attachment = Attachment.where(disk_filename: disk_filename, #
author_id: current_user.id, @attachment = Attachment.where(disk_filename: disk_filename,
cloud_url: remote_path).first author_id: current_user.id,
if @attachment.blank? cloud_url: remote_path).first
@attachment = Attachment.new if @attachment.blank?
@attachment.filename = upload_file.original_filename @attachment = Attachment.new
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size] @attachment.filename = upload_file.original_filename
@attachment.filesize = upload_file.tempfile.size @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.content_type = content_type @attachment.filesize = upload_file.tempfile.size
@attachment.digest = digest @attachment.content_type = content_type
@attachment.author_id = current_user.id @attachment.digest = digest
@attachment.disk_directory = month_folder @attachment.author_id = current_user.id
@attachment.cloud_url = remote_path @attachment.disk_directory = month_folder
@attachment.disk_directory = save_path @attachment.cloud_url = remote_path
@attachment.save! @attachment.disk_directory = save_path
else @attachment.save!
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}" else
end logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
render_json render_json
rescue => e
uid_logger_error(e.message)
tip_exception(e.message)
end
end end
def destroy def destroy

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

@ -118,7 +118,7 @@ class TPMBanner extends Component {
if (prevProps != this.props) { if (prevProps != this.props) {
let shixunopenprocess=window.localStorage.shixunopenprocess; let shixunopenprocess=window.localStorage.shixunopenprocess;
let openopenpublictype=window.localStorage.openopenpublictype; let openopenpublictype=window.localStorage.openopenpublictype;
if(this.props.shixunsDetails.shixun_status === 0 && this.props.identity < 5){ if(this.props.shixunsDetails&&this.props.shixunsDetails.shixun_status === 0 && this.props.identity < 5){
if(shixunopenprocess===undefined||shixunopenprocess===false){ if(shixunopenprocess===undefined||shixunopenprocess===false){
this.setState({ this.setState({
openknow:true openknow:true
@ -130,7 +130,7 @@ class TPMBanner extends Component {
} }
} }
if(this.props.shixunsDetails.shixun_status === 2 && this.props.shixunsDetails.public===0 && this.props.identity < 5){ if(this.props.shixunsDetails&&this.props.shixunsDetails.shixun_status === 2 && this.props.shixunsDetails&&this.props.shixunsDetails.public===0 && this.props.identity < 5){
if(openopenpublictype===undefined||openopenpublictype===false){ if(openopenpublictype===undefined||openopenpublictype===false){
this.setState({ this.setState({
openshowpublictype:true openshowpublictype:true

Loading…
Cancel
Save