From adce0c962762a82402a58042517ae16c8dc633be Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 09:39:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Areadme=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BD=BF=E7=94=A8owner=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f03215ace..5d8745397 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -235,9 +235,9 @@ class RepositoriesController < ApplicationController def readme if params[:filepath].present? - result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], @owner&.gitea_token) else - result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], @owner&.gitea_token) end @path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @readme = result[:status] === :success ? result[:body] : nil From 05b33171527ed3155f974486b64e0a82e7052238 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 17:13:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=98=E6=9B=B4=E8=B7=AF=E5=BE=84=E4=BD=BF=E7=94=A8?= =?UTF-8?q?base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitea/create_file_interactor.rb | 12 ++++++++-- .../gitea/delete_file_interactor.rb | 12 ++++++++-- .../gitea/update_file_interactor.rb | 22 ++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index cf753767c..70e2f6e81 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -25,7 +25,7 @@ module Gitea def run Contents::CreateForm.new(valid_params).validate! result = Gitea::Repository::Entries::CreateService.call(token, - owner, @params[:identifier], @params[:filepath], file_params) + owner, @params[:identifier], file_path, file_params) if result[:status] == :success @result = result[:body] @@ -50,9 +50,17 @@ module Gitea @result = response end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch] } diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index 9a48c9e56..103df6cd4 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::DeleteForm.new(valid_params).validate! - response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,17 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, sha: @params[:sha] } end diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index 7dc0c017f..38cfd98a8 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::UpdateForm.new(valid_params).validate! - response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,25 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + + def from_file_path + if @params[:base64_from_path].present? + Base64.decode64(params[:base64_from_path]) + else + @params[:from_path] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch], sha: @params[:sha] @@ -59,7 +75,7 @@ module Gitea branch: @params[:branch], sha: @params[:sha], new_branch: @params[:new_branch], - from_path: @params[:from_path], + from_path: from_file_path, message: @params[:message], content: Base64.encode64(@params[:content]) ).compact