merge from develop

This commit is contained in:
yystopf 2022-07-08 11:35:25 +08:00
commit ed22ff921e
2 changed files with 9 additions and 15 deletions

View File

@ -388,4 +388,4 @@ class RepositoriesController < ApplicationController
end
end
end
end

View File

@ -103,7 +103,7 @@ module RepositoriesHelper
end
end
# author hui.he
# author hui.he
def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name)
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
return nil if str.blank?
@ -120,23 +120,17 @@ module RepositoriesHelper
# 链接直接跳过不做替换
next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:') || s_content.blank?
ext = File.extname(s_content)[1..-1]
repo_regex = /([a-zA-Z0-9_-]{4,15})\/[a-zA-Z0-9_-]+$/
if (image_type?(ext) || download_type(ext)) && !s_content.to_s.end_with?('/')
if s_content.to_s.scan(repo_regex).size > 0
s_content = [base_url, '/', s_content].join
content = content.gsub(s[0], s_content)
else
s_content = File.expand_path(s_content, file_path)
s_content = s_content.split("#{Rails.root}/")[1]
# content = content.gsub(s[0], "/#{s_content}")
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join
content = content.gsub(s[0], s_content)
end
if (image_type?(ext) || download_type(ext)) && !ext.blank?
s_content = File.expand_path(s_content, file_path)
s_content = s_content.split("#{Rails.root}/")[1]
# content = content.gsub(s[0], "/#{s_content}")
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join
content = content.gsub(s[0], s_content)
else
path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/")
s_content = File.expand_path(s_content, path)
s_content = s_content.split("#{Rails.root}/")[1]
content = content.gsub(s[0], "/#{s_content}")
content = content.gsub('('+s[0]+')', '('+"/#{s_content}"+')')
end
rescue
next