|
|
@ -25,7 +25,7 @@ module GitHelper
|
|
|
|
decode_content =
|
|
|
|
decode_content =
|
|
|
|
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? && !content.blank?
|
|
|
|
raise("ERROR_UTF8")
|
|
|
|
raise("ERROR_UTF8")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
content.force_encoding('UTF-8')
|
|
|
|
content.force_encoding('UTF-8')
|
|
|
@ -36,7 +36,7 @@ module GitHelper
|
|
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
error_msg = e.message == "ERROR_UTF8" ? "文件无法预览" : "文档内容获取异常"
|
|
|
|
error_msg = e.message == "ERROR_UTF8" ? "文件编码异常,请将文件编码设置为UTF-8" : "文档内容获取异常"
|
|
|
|
error_status = e.message == "ERROR_UTF8" ? -2 : -1
|
|
|
|
error_status = e.message == "ERROR_UTF8" ? -2 : -1
|
|
|
|
raise Educoder::TipException.new(error_status, error_msg)
|
|
|
|
raise Educoder::TipException.new(error_status, error_msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|