readme GBK编码问题 执行顺序调整
This commit is contained in:
parent
8dc1c7f48c
commit
2f411e3421
|
@ -263,8 +263,9 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
@path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
||||||
@readme = result[:status] === :success ? result[:body] : nil
|
@readme = result[:status] === :success ? result[:body] : nil
|
||||||
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
# replace_content 前置,防止被content改写
|
||||||
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
|
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
Rails.logger.info("readme['replace_content']=================#{@readme['replace_content']}")
|
Rails.logger.info("readme['replace_content']=================#{@readme['replace_content']}")
|
||||||
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
||||||
rescue
|
rescue
|
||||||
|
|
|
@ -116,7 +116,6 @@ module RepositoriesHelper
|
||||||
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
|
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
|
||||||
return nil if str.blank?
|
return nil if str.blank?
|
||||||
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")
|
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")
|
||||||
Rails.logger.info("content2===#{content}")
|
|
||||||
# s_regex = /\s\!\[.*?\]\((.*?)\)\s/
|
# s_regex = /\s\!\[.*?\]\((.*?)\)\s/
|
||||||
s_regex_c = /`{1,2}[^`](.*?)`{1,2}/
|
s_regex_c = /`{1,2}[^`](.*?)`{1,2}/
|
||||||
s_regex = /```([\s\S]*?)```[\s]?/
|
s_regex = /```([\s\S]*?)```[\s]?/
|
||||||
|
@ -179,7 +178,6 @@ module RepositoriesHelper
|
||||||
after_ss_c_souces.each_with_index do |s, index|
|
after_ss_c_souces.each_with_index do |s, index|
|
||||||
content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}")
|
content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}")
|
||||||
end
|
end
|
||||||
Rails.logger.info("content3===#{content}")
|
|
||||||
return content
|
return content
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}")
|
Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}")
|
||||||
|
@ -200,7 +198,6 @@ module RepositoriesHelper
|
||||||
def readme_decode64_content(entry, owner, repo, ref, path=nil)
|
def readme_decode64_content(entry, owner, repo, ref, path=nil)
|
||||||
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
||||||
content = entry['content'].present? ? entry['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("content1===#{content}")
|
|
||||||
# readme_render_decode64_content(content, owner, repo, ref)
|
# readme_render_decode64_content(content, owner, repo, ref)
|
||||||
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue