|
|
|
@@ -104,8 +104,8 @@ module RepositoriesHelper |
|
|
|
end
|
|
|
|
|
|
|
|
# author hui.he
|
|
|
|
def new_readme_render_decode64_content(str, owner, repo, ref)
|
|
|
|
path = [owner&.login, repo&.identifier, 'tree', ref].join("/")
|
|
|
|
def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name)
|
|
|
|
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
|
|
|
|
return nil if str.blank?
|
|
|
|
content = Base64.decode64(str).force_encoding('UTF-8')
|
|
|
|
s_regex = /\[.*?\]\((.*?)\)/
|
|
|
|
@@ -119,15 +119,19 @@ module RepositoriesHelper |
|
|
|
s_content = s[0]
|
|
|
|
# 链接直接跳过不做替换
|
|
|
|
next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:')
|
|
|
|
# 路径替换
|
|
|
|
if s_content.starts_with?('./') || s_content.starts_with?("../") || s_content.starts_with?("/")
|
|
|
|
s_content = File.expand_path(s_content, path)
|
|
|
|
ext = File.extname(s_content)[1..-1]
|
|
|
|
|
|
|
|
if image_type?(ext) || download_type(ext)
|
|
|
|
s_content = File.expand_path(s_content, file_path)
|
|
|
|
s_content = s_content.split("#{Rails.root}/")[1]
|
|
|
|
content = content.gsub(s[0], "/#{s_content}")
|
|
|
|
else
|
|
|
|
# 图片资源替换
|
|
|
|
# content = content.gsub(s[0], "/#{s_content}")
|
|
|
|
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join
|
|
|
|
content = content.gsub(s[0], s_content)
|
|
|
|
else
|
|
|
|
path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/")
|
|
|
|
s_content = File.expand_path(s_content, path)
|
|
|
|
s_content = s_content.split("#{Rails.root}/")[1]
|
|
|
|
content = content.gsub(s[0], "/#{s_content}")
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
next
|
|
|
|
@@ -149,13 +153,21 @@ module RepositoriesHelper |
|
|
|
date.to_time.strftime("%Y-%m-%d %H:%M")
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme_decode64_content(entry, owner, repo, ref, path=nil)
|
|
|
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
|
|
|
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
|
|
|
Rails.logger.info("content===#{content}")
|
|
|
|
# readme_render_decode64_content(content, owner, repo, ref)
|
|
|
|
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def decode64_content(entry, owner, repo, ref, path=nil)
|
|
|
|
if is_readme?(entry['type'], entry['name'])
|
|
|
|
# content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
|
|
|
content = entry['content']
|
|
|
|
path = URI.escape(entry['path']).to_s.downcase.gsub("/readme.md","")
|
|
|
|
# readme_render_decode64_content(content, owner, repo, ref, path)
|
|
|
|
new_readme_render_decode64_content(content, owner, repo, ref)
|
|
|
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
|
|
|
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
|
|
|
Rails.logger.info("content===#{content}")
|
|
|
|
# readme_render_decode64_content(content, owner, repo, ref)
|
|
|
|
return Base64.decode64(content).force_encoding('UTF-8')
|
|
|
|
else
|
|
|
|
file_type = File.extname(entry['name'].to_s)[1..-1]
|
|
|
|
if image_type?(file_type)
|
|
|
|
|