From 9f269189a4f61df35ae55374646ec8f51f969d04 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:00:46 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E6=9F=A5=E8=AF=A2,=20=E5=AE=9A=E5=88=B6?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E7=AD=BE=E5=8F=AF=E6=9F=A5=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=A7=81=E6=9C=89=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 737cd7c2d..931f26145 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -77,7 +77,10 @@ class Projects::ListQuery < ApplicationQuery end def by_project_topic(items) - if params[:topic_name].present? + if params[:topic_name].present? && @current_user_id.present? + Project.visible.where(status: 1).with_project_topic_name(params[:topic_name].to_s.split(",")) + .or(Project.is_private.with_project_topic_name(params[:topic_name].to_s.split(",")).where(user_id: @current_user_id)) + elsif params[:topic_name].present? items.with_project_topic_name(params[:topic_name].to_s.split(",")) else items.with_project_topic(params[:topic_id]) From 39f234cc06c95eb62a16977df13c8f107e0dd3c6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:18:59 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fixed=20=E4=B8=AA=E4=BA=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E6=9D=A1=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=90=8D=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 ++-- app/queries/projects/list_query.rb | 5 +---- app/services/users/project_service.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ab7f1cdc6..5e036ff51 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) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 931f26145..737cd7c2d 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -77,10 +77,7 @@ class Projects::ListQuery < ApplicationQuery end def by_project_topic(items) - if params[:topic_name].present? && @current_user_id.present? - Project.visible.where(status: 1).with_project_topic_name(params[:topic_name].to_s.split(",")) - .or(Project.is_private.with_project_topic_name(params[:topic_name].to_s.split(",")).where(user_id: @current_user_id)) - elsif params[:topic_name].present? + if params[:topic_name].present? items.with_project_topic_name(params[:topic_name].to_s.split(",")) else items.with_project_topic(params[:topic_id]) 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 From 4d75e4a1741bfd05bec25419cd921b5d88611dc8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 16:31:19 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fixed=20=E4=B8=AA=E4=BA=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E6=9D=A1=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=90=8D=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/projects_controller.rb | 2 +- app/queries/projects/list_my_query.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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..df5fca8b6 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) From cbdbc4b25e6044d0e082a9facb5ea588a5e76906 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 29 Aug 2024 17:08:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fixed=20=E4=B8=AA=E4=BA=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E6=9D=A1=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=90=8D=E6=9F=A5=E8=AF=A2,=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_my_query.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index df5fca8b6..32a9ee787 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -88,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 From 973e18812cc35b099d22077d23c63bb61ee24715 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 4 Sep 2024 14:33:47 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Agitlink=E3=80=81?= =?UTF-8?q?gitea=E3=80=81gitcode=E7=9A=84token=E6=A0=A1=E9=AA=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/verify_auth_token_service.rb | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) 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 } From 033c65b46faea06aca1298b9145940822492a12c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 5 Sep 2024 09:18:07 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AThe=20target=20c?= =?UTF-8?q?ouldn't=20be=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5e036ff51..b3a0c3aa5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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