From a7384bc1c3bdd6a1678dbe189bb21c4a941437c3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 8 Oct 2022 18:44:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 79047b516..e9b767def 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -31,11 +31,11 @@ class AttachmentsController < ApplicationController def get_file normal_status(-1, "参数缺失") if params[:download_url].blank? - url = URI.encode(params[:download_url].to_s.gsub("http:", "https:")) + url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s) if url.starts_with?(base_url) domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] - url = url.split(base_url)[1].gsub("api", "repos").gsub('?filepath=', '/').gsub('&', '?') + url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?') request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join response = Faraday.get(request_url) filename = url.to_s.split("/").pop()