diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 7a855871c..eb73ea3f7 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -33,8 +33,9 @@ class AttachmentsController < ApplicationController normal_status(-1, "参数缺失") if params[:download_url].blank? url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s md5_file = Base64.strict_encode64(params[:download_url]) - tmp_path = "#{Rails.root}/public/files/#{Time.now.strftime('%Y%m%d%')}-#{md5_file}" - cache_key ="get_file:#{Time.now.strftime('%Y%m%d%')}:#{md5_file}" + FileUtils.mkdir_p("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/") unless Dir.exists?("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/") + tmp_path = "#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/#{Time.now.strftime('%Y%m%d')}-#{md5_file}" + cache_key ="get_file:#{Time.now.strftime('%Y%m%d')}:#{md5_file}" value = Rails.cache.read(cache_key) if value.to_i >= 5 && File.exist?(tmp_path) send_data(tmp_path, filename: filename, type: "application/octet-stream", disposition: 'attachment')