Merge branch 'develop' into dev_trustie_server
This commit is contained in:
commit
23f7439a8c
|
@ -5,7 +5,7 @@ class ProjectsController < ApplicationController
|
||||||
include Acceleratorable
|
include Acceleratorable
|
||||||
|
|
||||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
|
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
|
||||||
before_action :load_project, except: %i[index group_type_list migrate create recommend]
|
before_action :load_repository, except: %i[index group_type_list migrate create recommend]
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
|
||||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||||
before_action :get_ref, only: %i[entries sub_entries top_counts file]
|
before_action :get_ref, only: %i[entries sub_entries top_counts file archive]
|
||||||
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
||||||
before_action :get_statistics, only: %i[top_counts]
|
before_action :get_statistics, only: %i[top_counts]
|
||||||
|
|
||||||
|
@ -192,6 +192,19 @@ class RepositoriesController < ApplicationController
|
||||||
render json: languages_precentagable
|
render json: languages_precentagable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def archive
|
||||||
|
domain = Gitea.gitea_config[:domain]
|
||||||
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{params[:archive]}"
|
||||||
|
|
||||||
|
file_path = [domain, api_url, archive_url].join
|
||||||
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
||||||
|
|
||||||
|
return render_not_found if !request.format.zip? && !request.format.gzip?
|
||||||
|
|
||||||
|
redirect_to file_path
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
@ -266,7 +279,7 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
# uploadPushInfo
|
# uploadPushInfo
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_new_pr(params)
|
def create_new_pr(params)
|
||||||
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
||||||
local_params = {
|
local_params = {
|
||||||
|
|
|
@ -13,12 +13,12 @@ module ProjectsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_zip_url(project, archive_name)
|
def render_zip_url(owner, repository, archive)
|
||||||
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.zip"].join('/')
|
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.zip")].join
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_tar_url(project, archive_name)
|
def render_tar_url(owner, repository, archive)
|
||||||
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.tar.gz"].join('/')
|
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_http_url(project)
|
def render_http_url(project)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
class Gitea::Repository::ArchiveService < Gitea::ClientService
|
||||||
|
attr_reader :owner, :repo, :archive, :token
|
||||||
|
|
||||||
|
def initialize(owner, repo, archive, token=nil)
|
||||||
|
@owner = owner
|
||||||
|
@repo = repo
|
||||||
|
@archive = archive
|
||||||
|
@token = token
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = get(url, params)
|
||||||
|
response_payload(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
Hash.new.merge(token: token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{owner}/#{repo}/archive/#{archive}".freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def response_payload(response)
|
||||||
|
status = response.status
|
||||||
|
body = response&.body
|
||||||
|
|
||||||
|
log_error(status, body)
|
||||||
|
status_payload(status, body)
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_payload(status, body)
|
||||||
|
case status
|
||||||
|
when 200 then success
|
||||||
|
when 404 then error("你操作的链接不存在!")
|
||||||
|
else error("系统错误!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,8 +4,8 @@ json.array! @branches do |branch|
|
||||||
json.user_can_merge branch['user_can_merge']
|
json.user_can_merge branch['user_can_merge']
|
||||||
json.protected branch['protected']
|
json.protected branch['protected']
|
||||||
json.http_url render_http_url(@project)
|
json.http_url render_http_url(@project)
|
||||||
json.zip_url render_zip_url(@project, branch['name'])
|
json.zip_url render_zip_url(@owner, @repository, branch['name'])
|
||||||
json.tar_url render_tar_url(@project, branch['name'])
|
json.tar_url render_tar_url(@owner, @repository, branch['name'])
|
||||||
json.last_commit do
|
json.last_commit do
|
||||||
json.sha branch['commit']['id']
|
json.sha branch['commit']['id']
|
||||||
json.message branch['commit']['message']
|
json.message branch['commit']['message']
|
||||||
|
|
|
@ -42,8 +42,9 @@ if @project.forge?
|
||||||
#json.tags_count @tags_count
|
#json.tags_count @tags_count
|
||||||
#json.branches_count @branches_count
|
#json.branches_count @branches_count
|
||||||
json.commits_count @commits_count
|
json.commits_count @commits_count
|
||||||
json.zip_url render_zip_url(@project, @ref)
|
# json.zip_url archive_repositories_path(@owner&.login, @repository, @ref)
|
||||||
json.tar_url render_tar_url(@project, @ref)
|
json.zip_url render_zip_url(@owner, @repository, @ref)
|
||||||
|
json.tar_url render_tar_url(@owner, @repository, @ref)
|
||||||
json.entries do
|
json.entries do
|
||||||
json.array! @entries do |entry|
|
json.array! @entries do |entry|
|
||||||
json.name entry['name']
|
json.name entry['name']
|
||||||
|
|
|
@ -417,7 +417,6 @@ Rails.application.routes.draw do
|
||||||
member do
|
member do
|
||||||
get :files
|
get :files
|
||||||
get :detail
|
get :detail
|
||||||
get :archive
|
|
||||||
get :entries
|
get :entries
|
||||||
match :sub_entries, :via => [:get, :put]
|
match :sub_entries, :via => [:get, :put]
|
||||||
get :commits
|
get :commits
|
||||||
|
@ -432,6 +431,7 @@ Rails.application.routes.draw do
|
||||||
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
|
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
|
||||||
get 'readme'
|
get 'readme'
|
||||||
get 'languages'
|
get 'languages'
|
||||||
|
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue