From 04a8d194ccbce5138c8c92344312ff02368f0bf8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 17 Oct 2024 11:28:20 +0800 Subject: [PATCH] =?UTF-8?q?gitea=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=BC=93=E5=AD=98,=E6=9B=B4=E6=94=B9=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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')