From 5a28204b12e7058ee9eaaadc69c5fb1d5b39d943 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Oct 2023 14:17:08 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E6=96=87=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=96=87=E6=9C=AC=E5=88=A4=E6=96=AD=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E6=98=BE=E7=A4=BA=E5=A4=9A=E7=A7=8D=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 6 ++++++ app/views/repositories/_simple_entry.json.jbuilder | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ee783da87..f364c11ff 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -19,6 +19,10 @@ module RepositoriesHelper default_type.include?(str.to_s.gsub("\r", "").downcase) end + def is_text_file?(entry) + entry['is_text_file'] + end + def is_readme?(type, str) return false if type != 'file' || str.blank? readme_types = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"] @@ -232,6 +236,8 @@ module RepositoriesHelper # Rails.logger.info("content===#{content}") 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') + elsif entry['is_text_file'] == true + return render_decode64_content(entry['content']) else file_type = File.extname(entry['name'].to_s)[1..-1] if image_type?(file_type) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 9ad5e3fc2..56b75c198 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -2,7 +2,8 @@ if @project.forge? is_dir = @sub_entries.is_a?(Array) file_name = entry['name'] file_type = file_name.starts_with?('.') ? file_name[1..-1] : File.extname(file_name.to_s)[1..-1] - direct_download = %w(makefile dockerfile readme).exclude?(file_name.to_s.downcase) && download_type(file_type) + # direct_download = %w(makefile dockerfile readme).exclude?(file_name.to_s.downcase) && download_type(file_type) + direct_download = entry['is_text_file'] == true ? false : true image_type = image_type?(file_type) json.name file_name json.sha entry['sha']