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 e50bd22d3..b86226454 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/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 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 dcce71920..8b943f543 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -534,7 +534,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