fix: download file need authorize
This commit is contained in:
parent
d5de6aa66b
commit
90ace8b753
|
@ -206,6 +206,17 @@ class RepositoriesController < ApplicationController
|
||||||
redirect_to file_path
|
redirect_to file_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def raw
|
||||||
|
domain = Gitea.gitea_config[:domain]
|
||||||
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
|
||||||
|
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{params[:filepath]}?ref=#{params[:ref]}"
|
||||||
|
file_path = [domain, api_url, url].join
|
||||||
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") if @repository.hidden?
|
||||||
|
|
||||||
|
redirect_to file_path
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
|
|
@ -21,6 +21,10 @@ module ProjectsHelper
|
||||||
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_download_file_url(owner, repository, filepath, ref)
|
||||||
|
[base_url, "/api/#{owner&.login}/#{repository.identifier}/raw?filepath=#{filepath}&ref=#{ref}"].join
|
||||||
|
end
|
||||||
|
|
||||||
def render_http_url(project)
|
def render_http_url(project)
|
||||||
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,8 @@ if @project.forge?
|
||||||
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
||||||
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
||||||
else
|
else
|
||||||
entry['download_url']
|
# entry['download_url']
|
||||||
|
render_download_file_url(@owner, @repository, entry['path'].to_s, @ref)
|
||||||
end
|
end
|
||||||
json.download_url download_url
|
json.download_url download_url
|
||||||
|
|
||||||
|
|
|
@ -434,6 +434,7 @@ Rails.application.routes.draw do
|
||||||
get 'readme'
|
get 'readme'
|
||||||
get 'languages'
|
get 'languages'
|
||||||
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
||||||
|
get 'raw', to: 'repositories#raw', as: "raw"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue