Merge branch 'standalone_develop' into pre_trustie_server

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

View File

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

View File

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