From d154f0aecc38c22b3982fd27a987e488a22f2548 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Jul 2022 11:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20readme=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 2 +- app/helpers/repositories_helper.rb | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 51fa37aca..fdec82b66 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -99,7 +99,7 @@ class RepositoriesController < ApplicationController end end else - @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" + @path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref) if interactor.success? result = interactor.result diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 45eccca90..998629c9d 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -104,23 +104,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