Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
yystopf 2024-09-06 10:23:45 +08:00
commit 2a1b9792cd
5 changed files with 85 additions and 15 deletions

View File

@ -43,11 +43,11 @@ class ProjectsController < ApplicationController
category_id = params[:category_id] category_id = params[:category_id]
@total_count = @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性能问题处理 # 默认查询时count性能问题处理
not_category_count = Project.where(project_category_id: nil).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 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 @projects.total_count
else else
cate = ProjectCategory.find_by(id: category_id) cate = ProjectCategory.find_by(id: category_id)
@ -314,8 +314,8 @@ class ProjectsController < ApplicationController
def simple def simple
if !@project.common? && @project&.repository&.mirror&.waiting? if !@project.common? && @project&.repository&.mirror&.waiting?
gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue nil
if !gitea_result["empty"] if gitea_result.present? && !gitea_result["empty"]
@project&.update_columns(gpid: gitea_result["id"]) @project&.update_columns(gpid: gitea_result["id"])
@project&.repository&.mirror&.succeeded! @project&.repository&.mirror&.succeeded!
project_id = @project&.id project_id = @project&.id

View File

@ -20,6 +20,6 @@ class Users::ProjectsController < Users::BaseController
private private
def query_params def query_params
params.permit(:category, :status, :sort_direction) params.permit(:category, :status, :sort_direction, :topic_name)
end end
end end

View File

@ -63,6 +63,15 @@ class Projects::ListMyQuery < ApplicationQuery
projects = projects.sync_mirror projects = projects.sync_mirror
end 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('') keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
q = projects.ransack(name_or_identifier_cont: keywords) q = projects.ransack(name_or_identifier_cont: keywords)
@ -79,6 +88,8 @@ class Projects::ListMyQuery < ApplicationQuery
else else
if @home_top_ids.present? if @home_top_ids.present?
scope = scope.distinct.order("FIELD(projects.id, #{@home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}") scope = scope.distinct.order("FIELD(projects.id, #{@home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}")
elsif params[:topic_name].present?
scope = scope.distinct.order("project_topics.id asc, projects.#{sort} #{sort_direction}")
else else
scope = scope.distinct.order("projects.#{sort} #{sort_direction}") scope = scope.distinct.order("projects.#{sort} #{sort_direction}")
end end

View File

@ -36,16 +36,66 @@ class Projects::VerifyAuthTokenService < ApplicationService
gitlab_verify gitlab_verify
when "gitee.com" when "gitee.com"
gitee_verify gitee_verify
when "gitlink.org.cn"
gitlink_verify
when "gitea.com"
gitea_verify
when "gitcode.com"
gitcode_verify
else
@success = nil
end end
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 def gitee_verify
url = "/api/v5/repos/#{@owner}/#{@repo}" url = "/api/v5/repos/#{@owner}/#{@repo}"
api_url= "https://gitee.com" api_url= "https://gitee.com"
client = Faraday.new(url: api_url) client = Faraday.new(url: api_url)
client.options["open_timeout"] = 1 client.options["open_timeout"] = 100
client.options["timeout"] = 1 client.options["timeout"] = 100
client.options["write_timeout"] = 1 client.options["write_timeout"] = 100
req_params={ req_params={
access_token: @token, access_token: @token,
owner: @owner, owner: @owner,
@ -59,9 +109,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
url = "/octocat" url = "/octocat"
api_url= "https://api.github.com" api_url= "https://api.github.com"
client = Faraday.new(url: api_url) client = Faraday.new(url: api_url)
client.options["open_timeout"] = 1 client.options["open_timeout"] = 100
client.options["timeout"] = 1 client.options["timeout"] = 100
client.options["write_timeout"] = 1 client.options["write_timeout"] = 100
client.headers["Authorization"] = "Bearer #{@token}" client.headers["Authorization"] = "Bearer #{@token}"
response = client.public_send("get", url) response = client.public_send("get", url)
@success = true if response.status == 200 @success = true if response.status == 200
@ -71,9 +121,9 @@ class Projects::VerifyAuthTokenService < ApplicationService
url = "/api/v4/projects" url = "/api/v4/projects"
api_url= "https://gitlab.com" api_url= "https://gitlab.com"
client = Faraday.new(url: api_url) client = Faraday.new(url: api_url)
client.options["open_timeout"] = 1 client.options["open_timeout"] = 100
client.options["timeout"] = 1 client.options["timeout"] = 100
client.options["write_timeout"] = 1 client.options["write_timeout"] = 100
req_params={ req_params={
private_token: @token private_token: @token
} }

View File

@ -20,6 +20,7 @@ class Users::ProjectService
projects = category_filter(projects) projects = category_filter(projects)
projects = status_filter(projects) projects = status_filter(projects)
projects = by_project_topic(projects)
custom_sort(projects, params[:sort_by], params[:sort_direction]) custom_sort(projects, params[:sort_by], params[:sort_direction])
end end
@ -45,6 +46,14 @@ class Users::ProjectService
end end
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? def self_or_admin?
User.current.id == user.id || User.current.admin? User.current.id == user.id || User.current.admin?
end end