From ccede16716d98a0ac01fb05fbae74fb0cf8b64ef Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 14:41:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aevents=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder | 2 +- app/views/projects/webhooks/create.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index 43d602d1f..1eab68518 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -3,7 +3,7 @@ json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] -json.events webhook["events"] +json.events webhook["events"].collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} json.active webhook['active'] json.branch_filter webhook['branch_filter'] json.created_at format_time(webhook['created_at'].to_time) \ No newline at end of file diff --git a/app/views/projects/webhooks/create.json.jbuilder b/app/views/projects/webhooks/create.json.jbuilder index 6d6dde31f..26ccd52fa 100644 --- a/app/views/projects/webhooks/create.json.jbuilder +++ b/app/views/projects/webhooks/create.json.jbuilder @@ -2,6 +2,6 @@ json.id @webhook["id"] json.type @webhook["type"] json.content_type @webhook["config"]["content_type"] json.url @webhook["config"]["url"] -json.events @webhook["events"] +json.events @webhook["events"].collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} json.active @webhook["active"] json.create_time @webhook["created_at"].to_time.strftime("%Y-%m-%d %H:%M:%S") \ No newline at end of file From 083085051850d6a6e656ca7c010b58230c3cae4d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 14:51:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6=E4=BB=A5=E5=8F=8A=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 11 +++++++---- app/controllers/repositories_controller.rb | 2 +- app/helpers/projects_helper.rb | 2 +- .../repositories/_simple_entry.json.jbuilder | 17 +++++++++-------- config/routes.rb | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 941dcf35f..0cdba3847 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -31,14 +31,17 @@ class AttachmentsController < ApplicationController def get_file normal_status(-1, "参数缺失") if params[:download_url].blank? - url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s) + url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo") domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] - url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?') - request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + url = ("/repos"+url.split(base_url + "/api")[1]) + filepath, ref = url.split("/")[-1].split("?") + url.gsub!(url.split("/")[-1], '') + puts filepath + request_url = [domain, api_url, url, CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join response = Faraday.get(request_url) - filename = url.to_s.split("/").pop() + filename = filepath else response = Faraday.get(url) filename = params[:download_url].to_s.split("/").pop() diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5d8745397..f80e00b6f 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -273,7 +273,7 @@ class RepositoriesController < ApplicationController domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] - url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}" + url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}" file_path = [domain, api_url, url].join file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("&") diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5ed680ba3..aa905ebc9 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -22,7 +22,7 @@ module ProjectsHelper end def render_download_file_url(owner, repository, filepath, ref) - [base_url, "/api/#{owner&.login}/#{repository.identifier}/raw?filepath=#{filepath}&ref=#{ref}"].join + [base_url, "/api/#{owner&.login}/#{repository.identifier}/raw/#{CGI.escape(filepath)}?ref=#{CGI.escape(ref)}"].join end def render_http_url(project) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 42342f07b..9ad5e3fc2 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -17,14 +17,15 @@ if @project.forge? json.content (direct_download || image_type || is_dir) ? nil : decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] - download_url = - if image_type - dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/') - is_dir ? "" : render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref)) - else - # entry['download_url'] - is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) - end + download_url = is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) + # if image_type + # # dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/') + # # is_dir ? "" : render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref)) + # is_dir ? "" : render_gitea_raw_url(entry['download_url']) + # else + # # entry['download_url'] + # is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) + # end json.download_url download_url json.direct_download direct_download diff --git a/config/routes.rb b/config/routes.rb index 7e69c2e38..0123654cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -507,7 +507,7 @@ Rails.application.routes.draw do get 'readme' get 'languages' get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ } - get 'raw', to: 'repositories#raw', as: "raw" + get 'raw/*filepath', to: 'repositories#raw', as: "raw", constraints: { filepath: /.+/} end end