| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||