fix: readme private file path use authorize

This commit is contained in:
yystopf 2021-12-21 14:24:27 +08:00
parent 7849bd0ebf
commit 45a77e5c07
1 changed files with 9 additions and 8 deletions

View File

@ -45,7 +45,7 @@ module RepositoriesHelper
end end
end end
def readme_render_decode64_content(str, path) def readme_render_decode64_content(str, owner, repo, ref)
return nil if str.blank? return nil if str.blank?
begin begin
content = Base64.decode64(str).force_encoding('UTF-8') content = Base64.decode64(str).force_encoding('UTF-8')
@ -63,13 +63,14 @@ module RepositoriesHelper
if remove_title.length > 0 if remove_title.length > 0
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
end end
if r_content.include?("?") # if r_content.include?("?")
new_r_content = r_content + "&raw=true" # new_r_content = r_content + "&raw=true"
else # else
new_r_content = r_content + "?raw=true" # new_r_content = r_content + "?raw=true"
end # end
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
new_r_content = "#{path}" + new_r_content # new_r_content = "#{path}" + new_r_content
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{r_content}&ref=#{ref}"].join
end end
content = content.gsub(/#{r_content}/, new_r_content) content = content.gsub(/#{r_content}/, new_r_content)
end end
@ -94,7 +95,7 @@ module RepositoriesHelper
def decode64_content(entry, owner, repo, ref, path=nil) def decode64_content(entry, owner, repo, ref, path=nil)
if is_readme?(entry['type'], entry['name']) if is_readme?(entry['type'], entry['name'])
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
readme_render_decode64_content(content, path) readme_render_decode64_content(content, owner, repo, ref)
else else
file_type = File.extname(entry['name'].to_s)[1..-1] file_type = File.extname(entry['name'].to_s)[1..-1]
if image_type?(file_type) if image_type?(file_type)