|
|
@ -13,7 +13,7 @@ module GitHelper
|
|
|
|
|
|
|
|
|
|
|
|
content = GitService.file_content(repo_path: repo_path, path: path)
|
|
|
|
content = GitService.file_content(repo_path: repo_path, path: path)
|
|
|
|
|
|
|
|
|
|
|
|
Rails.logger.info("git file content: content is #{content}")
|
|
|
|
#Rails.logger.info("git file content: content is #{content}")
|
|
|
|
decode_content = nil
|
|
|
|
decode_content = nil
|
|
|
|
if content.present?
|
|
|
|
if content.present?
|
|
|
|
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
|
|
|
|
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
|
|
|
@ -26,7 +26,7 @@ module GitHelper
|
|
|
|
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
|
|
|
|
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
|
|
|
|
content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
|
|
|
|
content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
|
|
|
|
elsif cd['encoding'].blank?
|
|
|
|
elsif cd['encoding'].blank?
|
|
|
|
raise("无效的utf-8文件")
|
|
|
|
raise("ERROR_UTF8")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Rails.logger.info("####encoding:#{content.encoding}")
|
|
|
|
Rails.logger.info("####encoding:#{content.encoding}")
|
|
|
|
content.force_encoding('UTF-8')
|
|
|
|
content.force_encoding('UTF-8')
|
|
|
@ -37,7 +37,8 @@ module GitHelper
|
|
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
raise Educoder::TipException.new("文档内容获取异常")
|
|
|
|
error_msg = e.message == "ERROR_UTF8" ? "文件无法预览" : "文档内容获取异常"
|
|
|
|
|
|
|
|
raise Educoder::TipException.new(error_msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|