|
|
|
@@ -55,7 +55,7 @@ module RepositoriesHelper |
|
|
|
def readme_render_decode64_content(str, owner, repo, ref, path) |
|
|
|
return nil if str.blank? |
|
|
|
begin |
|
|
|
content = Base64.decode64(str).force_encoding('UTF-8') |
|
|
|
content = Base64.decode64(content).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") |
|
|
|
|
|
|
|
c_regex = /\!\[.*?\]\((.*?)\)/ |
|
|
|
src_regex = /src=\"(.*?)\"/ |
|
|
|
@@ -115,7 +115,7 @@ module RepositoriesHelper |
|
|
|
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') |
|
|
|
content = Base64.decode64(str).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") |
|
|
|
# s_regex = /\s\!\[.*?\]\((.*?)\)\s/ |
|
|
|
s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ |
|
|
|
s_regex = /```([\s\S]*?)```[\s]?/ |
|
|
|
@@ -178,9 +178,10 @@ module RepositoriesHelper |
|
|
|
after_ss_c_souces.each_with_index do |s, index| |
|
|
|
content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") |
|
|
|
end |
|
|
|
|
|
|
|
return content |
|
|
|
rescue |
|
|
|
rescue Exception => e |
|
|
|
Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}") |
|
|
|
# e.backtrace.each { |msg| Rails.logger.error(msg) } |
|
|
|
return str |
|
|
|
end |
|
|
|
|
|
|
|
@@ -196,8 +197,7 @@ module RepositoriesHelper |
|
|
|
|
|
|
|
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}") |
|
|
|
content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] |
|
|
|
# readme_render_decode64_content(content, owner, repo, ref) |
|
|
|
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) |
|
|
|
end |
|
|
|
@@ -205,9 +205,9 @@ module RepositoriesHelper |
|
|
|
def decode64_content(entry, owner, repo, ref, path=nil) |
|
|
|
if is_readme?(entry['type'], entry['name']) |
|
|
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") |
|
|
|
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] |
|
|
|
content = entry['content'].present? ? entry['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("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding? |
|
|
|
return Base64.decode64(content).force_encoding('UTF-8') |
|
|
|
else |
|
|
|
file_type = File.extname(entry['name'].to_s)[1..-1] |
|
|
|
|