diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ab7f1cdc6..b3a0c3aa5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -43,11 +43,11 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? && params[:search].blank? && params[:topic_id].blank? + if category_id.blank? && params[:search].blank? && params[:topic_id].blank? && params[:topic_name].blank? # 默认查询时count性能问题处理 not_category_count = Project.where(project_category_id: nil).count ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count - elsif params[:search].present? || params[:topic_id].present? + elsif params[:search].present? || params[:topic_id].present? || params[:topic_name].present? @projects.total_count else cate = ProjectCategory.find_by(id: category_id) @@ -314,8 +314,8 @@ class ProjectsController < ApplicationController def simple if !@project.common? && @project&.repository&.mirror&.waiting? - gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) - if !gitea_result["empty"] + gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue nil + if gitea_result.present? && !gitea_result["empty"] @project&.update_columns(gpid: gitea_result["id"]) @project&.repository&.mirror&.succeeded! project_id = @project&.id diff --git a/app/controllers/users/projects_controller.rb b/app/controllers/users/projects_controller.rb index 8ffa8fa85..55ff17192 100644 --- a/app/controllers/users/projects_controller.rb +++ b/app/controllers/users/projects_controller.rb @@ -20,6 +20,6 @@ class Users::ProjectsController < Users::BaseController private def query_params - params.permit(:category, :status, :sort_direction) + params.permit(:category, :status, :sort_direction, :topic_name) end end \ No newline at end of file diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index b81d5542b..32a9ee787 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -63,6 +63,15 @@ class Projects::ListMyQuery < ApplicationQuery projects = projects.sync_mirror end + if params[:topic_name].present? + projects = projects.with_project_topic_name(params[:topic_name].to_s.split(",")) + end + + if params[:topic_id].present? + projects = projects.with_project_topic(params[:topic_id]) + end + + # 表情处理 keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') q = projects.ransack(name_or_identifier_cont: keywords) @@ -79,7 +88,9 @@ class Projects::ListMyQuery < ApplicationQuery else if @home_top_ids.present? scope = scope.distinct.order("FIELD(projects.id, #{@home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}") - else + elsif params[:topic_name].present? + scope = scope.distinct.order("project_topics.id asc, projects.#{sort} #{sort_direction}") + else scope = scope.distinct.order("projects.#{sort} #{sort_direction}") end end diff --git a/app/services/projects/verify_auth_token_service.rb b/app/services/projects/verify_auth_token_service.rb index 36dcb106f..1f6b7a076 100644 --- a/app/services/projects/verify_auth_token_service.rb +++ b/app/services/projects/verify_auth_token_service.rb @@ -36,16 +36,66 @@ class Projects::VerifyAuthTokenService < ApplicationService gitlab_verify when "gitee.com" gitee_verify + when "gitlink.org.cn" + gitlink_verify + when "gitea.com" + gitea_verify + when "gitcode.com" + gitcode_verify + else + @success = nil end end + def gitcode_verify + url = "/api/v5/user" + api_url = "https://api.gitcode.com" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 + req_params={ + access_token: @token + } + response = client.public_send("get", url, req_params) + @success = true if response.status == 200 + end + + def gitea_verify + url = "/api/v1/user" + api_url = "https://gitea.com" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 + req_params={ + token: @token + } + response = client.public_send("get", url, req_params) + @success = true if response.status == 200 + end + + def gitlink_verify + url = "/api/v1/user" + api_url = "https://cdn05042023.gitlink.org.cn" + client = Faraday.new(url: api_url) + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 + req_params={ + token: @token + } + response = client.public_send("get", url, req_params) + @success = true if response.status == 200 + end + def gitee_verify url = "/api/v5/repos/#{@owner}/#{@repo}" api_url= "https://gitee.com" client = Faraday.new(url: api_url) - client.options["open_timeout"] = 1 - client.options["timeout"] = 1 - client.options["write_timeout"] = 1 + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 req_params={ access_token: @token, owner: @owner, @@ -59,9 +109,9 @@ class Projects::VerifyAuthTokenService < ApplicationService url = "/octocat" api_url= "https://api.github.com" client = Faraday.new(url: api_url) - client.options["open_timeout"] = 1 - client.options["timeout"] = 1 - client.options["write_timeout"] = 1 + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 client.headers["Authorization"] = "Bearer #{@token}" response = client.public_send("get", url) @success = true if response.status == 200 @@ -71,9 +121,9 @@ class Projects::VerifyAuthTokenService < ApplicationService url = "/api/v4/projects" api_url= "https://gitlab.com" client = Faraday.new(url: api_url) - client.options["open_timeout"] = 1 - client.options["timeout"] = 1 - client.options["write_timeout"] = 1 + client.options["open_timeout"] = 100 + client.options["timeout"] = 100 + client.options["write_timeout"] = 100 req_params={ private_token: @token } diff --git a/app/services/users/project_service.rb b/app/services/users/project_service.rb index f08b96009..86b2e9bb2 100644 --- a/app/services/users/project_service.rb +++ b/app/services/users/project_service.rb @@ -20,6 +20,7 @@ class Users::ProjectService projects = category_filter(projects) projects = status_filter(projects) + projects = by_project_topic(projects) custom_sort(projects, params[:sort_by], params[:sort_direction]) end @@ -45,6 +46,14 @@ class Users::ProjectService end end + def by_project_topic(items) + if params[:topic_name].present? + items.with_project_topic_name(params[:topic_name].to_s.split(",")) + else + items.with_project_topic(params[:topic_id]) + end + end + def self_or_admin? User.current.id == user.id || User.current.admin? end