diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0c9c49621..a4ceeac09 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -18,9 +18,9 @@ class AttachmentsController < ApplicationController pdf_attachment = params[:disposition] || "attachment" if pdf_attachment == "inline" - send_file absolute_path(local_path(@file)),filename: @file.filename, disposition: 'inline',type: 'application/pdf' + send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf' else - send_file(absolute_path(local_path(@file)), filename: @file.filename,stream:false, type: @file.content_type.presence || 'application/octet-stream') + send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream') end update_downloads(@file) end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 37884e40b..a918f4e0a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -27,12 +27,21 @@ class Attachment < ApplicationRecord validates_length_of :description, maximum: 100 + DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + def diskfile File.join(File.join(Rails.root, "files"), disk_directory.to_s, disk_filename.to_s) end def title - filename + title = filename + if container.is_a?(StudentWork) && author_id != User.current.id + course = container&.homework_common&.course + unless User.current.teacher_of_course?(course) + title = "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{DCODES.sample(8).join}" + File.extname(filename) + end + end + title end def downloads_count diff --git a/app/models/competition.rb b/app/models/competition.rb index 23fa268ec..96fd14c1c 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -165,7 +165,7 @@ class Competition < ApplicationRecord def get_module_name type case type - when 'home' then '首页' + when 'home' then '赛制介绍' when 'enroll' then '报名' when 'inform' then '通知公告' when 'chart' then '排行榜' diff --git a/app/views/student_works/show.json.jbuilder b/app/views/student_works/show.json.jbuilder index 9bafbe93e..7b3a91b5e 100644 --- a/app/views/student_works/show.json.jbuilder +++ b/app/views/student_works/show.json.jbuilder @@ -11,7 +11,7 @@ json.update_user_name @is_evaluation ? "匿名" : @work.update_user.try(:real_na json.update_atta @homework.late_duration && @is_author json.attachments @attachments do |atta| - json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: false} + json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: false, } end unless @is_evaluation