| @@ -11,7 +11,7 @@ module RepositoriesHelper | |||||
| end | end | ||||
| def download_type(str) | 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) | default_type.include?(str&.downcase) | ||||
| end | end | ||||
| @@ -20,8 +20,8 @@ module RepositoriesHelper | |||||
| default_type.include?(str&.downcase) | default_type.include?(str&.downcase) | ||||
| end | 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 = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"] | ||||
| readme_types.include?(str.to_s.downcase) | readme_types.include?(str.to_s.downcase) | ||||
| end | end | ||||
| @@ -72,4 +72,15 @@ module RepositoriesHelper | |||||
| def render_format_time_with_date(date) | def render_format_time_with_date(date) | ||||
| date.to_time.strftime("%Y-%m-%d %H:%M") | date.to_time.strftime("%Y-%m-%d %H:%M") | ||||
| end | 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 | end | ||||
| @@ -8,12 +8,13 @@ if @project.forge? | |||||
| json.path entry['path'] | json.path entry['path'] | ||||
| json.type entry['type'] | json.type entry['type'] | ||||
| json.size entry['size'] | 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.target entry['target'] | ||||
| json.download_url entry['download_url'] | json.download_url entry['download_url'] | ||||
| json.direct_download direct_download | json.direct_download direct_download | ||||
| json.image_type image_type | 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['latest_commit'] | ||||
| if entry['type'] != 'file' | if entry['type'] != 'file' | ||||
| json.partial! 'last_commit', entry: entry | json.partial! 'last_commit', entry: entry | ||||
| @@ -51,17 +51,8 @@ if @project.forge? | |||||
| json.sha entry['sha'] | json.sha entry['sha'] | ||||
| json.type entry['type'] | json.type entry['type'] | ||||
| json.size entry['size'] | 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'] | json.target entry['target'] | ||||
| if entry['latest_commit'] | if entry['latest_commit'] | ||||
| json.partial! 'last_commit', entry: entry | json.partial! 'last_commit', entry: entry | ||||