FIX get readme file bug

This commit is contained in:
Jasder 2021-01-15 18:36:19 +08:00
parent 232f26ea3b
commit 30138cc1fa
3 changed files with 19 additions and 16 deletions

View File

@ -11,7 +11,7 @@ module RepositoriesHelper
end
def download_type(str)
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata doc docx mpp vsdx)
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata doc docx mpp vsdx dot)
default_type.include?(str&.downcase)
end
@ -20,8 +20,8 @@ module RepositoriesHelper
default_type.include?(str&.downcase)
end
def is_readme_type?(str)
return false if str.blank?
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"]
readme_types.include?(str.to_s.downcase)
end
@ -72,4 +72,15 @@ module RepositoriesHelper
def render_format_time_with_date(date)
date.to_time.strftime("%Y-%m-%d %H:%M")
end
def decode64_content(entry, owner, repo, ref, path=nil)
if is_readme?(entry['type'], entry['name'])
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, entry['path'], ref: ref)['content']
readme_render_decode64_content(content, path)
else
file_type = entry['name'].to_s.split(".").last
return entry['content'] if download_type(file_type)
render_decode64_content(entry['content'])
end
end
end

View File

@ -8,12 +8,13 @@ if @project.forge?
json.path entry['path']
json.type entry['type']
json.size entry['size']
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']) : ""
json.content decode64_content(entry, @owner, @repository, @ref)
json.target entry['target']
json.download_url entry['download_url']
json.direct_download direct_download
json.image_type image_type
json.is_readme_file is_readme_type?(file_name)
json.is_readme_file is_readme?(entry['type'], entry['name'])
if entry['latest_commit']
if entry['type'] != 'file'
json.partial! 'last_commit', entry: entry

View File

@ -51,17 +51,8 @@ if @project.forge?
json.sha entry['sha']
json.type entry['type']
json.size entry['size']
content =
if is_readme_type?(entry['name'])
is_readme_file = true
content = Gitea::Repository::Entries::GetService.call(@owner, @project.identifier, entry['name'], ref: @ref)['content']
readme_render_decode64_content(content, @path)
else
is_readme_file = false
entry['content']
end
json.is_readme_file is_readme_file
json.content content
json.is_readme_file is_readme?(entry['type'], entry['name'])
json.content decode64_content(entry, @owner, @repository, @ref, @path)
json.target entry['target']
if entry['latest_commit']
json.partial! 'last_commit', entry: entry