diff --git a/app/controllers/api/v1/project_topics_controller.rb b/app/controllers/api/v1/project_topics_controller.rb index 46ae4cee0..daa0a5a66 100644 --- a/app/controllers/api/v1/project_topics_controller.rb +++ b/app/controllers/api/v1/project_topics_controller.rb @@ -2,7 +2,7 @@ class Api::V1::ProjectTopicsController < Api::V1::BaseController def index @project_topics = ProjectTopic - @project_topics = @project_topics.ransack(name_cont: params[:keyword]) if params[:keyword].present? + @project_topics = @project_topics.ransack(name_cont: params[:keyword]).result if params[:keyword].present? # @project_topics = @project_topics.includes(:projects) @project_topics = kaminary_select_paginate(@project_topics) end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ad7acc986..38d810c49 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -368,6 +368,7 @@ class RepositoriesController < ApplicationController def content_params { + base64_filepath: params[:base64_filepath], filepath: params[:filepath], branch: params[:branch], new_branch: params[:new_branch], diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index 70e2f6e81..f3db28417 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -56,6 +56,8 @@ module Gitea else @params[:filepath] end + rescue + @params[:filepath] end def valid_params diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index f94b8a205..84cd92ff6 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -51,10 +51,12 @@ module Gitea def file_path if @params[:base64_filepath].present? - Base64.decode64(params[:base64_filepath]) + Base64.strict_decode64(params[:base64_filepath]) else @params[:filepath] end + rescue + @params[:filepath] end def valid_params diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index 1b729e2c8..321f00ade 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -50,18 +50,22 @@ module Gitea def file_path if @params[:base64_filepath].present? - Base64.decode64(params[:base64_filepath]) + Base64.strict_decode64(params[:base64_filepath]) else @params[:filepath] end + rescue + @params[:filepath] end def from_file_path if @params[:base64_from_path].present? - Base64.decode64(params[:base64_from_path]) + Base64.strict_decode64(params[:base64_from_path]) else @params[:from_path] end + rescue + @params[:from_path] end def valid_params diff --git a/app/services/gitea/repository/entries/create_service.rb b/app/services/gitea/repository/entries/create_service.rb index 406106744..6a80e1d62 100644 --- a/app/services/gitea/repository/entries/create_service.rb +++ b/app/services/gitea/repository/entries/create_service.rb @@ -61,7 +61,9 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService else if json_parse!(body)["message"].present? && json_parse!(body)["message"].starts_with?("branch already exists") error("#{@body[:new_branch]}分支已存在!") - else + elsif json_parse!(body)["message"].present? && json_parse!(body)["message"].starts_with?("illegal base64 data at input byte 4") + error("文件内容必须是base64编码的!") + else error("#{filepath}文件已存在,不能重复创建!") end end diff --git a/app/services/pull_requests/create_service.rb b/app/services/pull_requests/create_service.rb index 31e6b1fd8..1723c7f29 100644 --- a/app/services/pull_requests/create_service.rb +++ b/app/services/pull_requests/create_service.rb @@ -187,7 +187,7 @@ class PullRequests::CreateService < ApplicationService def compare_head_base! head = pull_request.is_original && @params[:merge_user_login] ? "#{@params[:merge_user_login]}/#{@params[:merge_project_identifier]}:#{@params[:head]}" : @params[:head] compare_result = Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(@params[:base]), Addressable::URI.escape(head), @current_user.gitea_token) - raise '分支内容相同,无需创建合并请求' if compare_result["Commits"].blank? && compare_result["Diff"].blank? + raise '分支内容相同,无需创建合并请求' if compare_result["Commits"].blank? && compare_result["Diff"].blank? && compare_result["FilesCount"].zero? end def is_original diff --git a/app/services/repositories/migrate_service.rb b/app/services/repositories/migrate_service.rb index 4c3d4668d..89145e33f 100644 --- a/app/services/repositories/migrate_service.rb +++ b/app/services/repositories/migrate_service.rb @@ -32,7 +32,7 @@ class Repositories::MigrateService < ApplicationService private: params[:hidden], mirror: wrapper_mirror || false, auth_username: params[:login], - auth_password: Base64.decode64(params[:password] || ""), + auth_password: base64_decode_password, auth_token: params[:auth_token], service: params[:service] || 'git', } @@ -41,4 +41,10 @@ class Repositories::MigrateService < ApplicationService def wrapper_mirror ActiveModel::Type::Boolean.new.cast(params[:is_mirror]) end + + def base64_decode_password + Base64.strict_decode64(params[:password] || "") + rescue + params[:password] + end end