fixed: 1.readme加载不正常, 2.文件目录加载性能优化

This commit is contained in:
xiaoxiaoqiong 2022-03-18 16:52:23 +08:00
parent 23dc2d7fb6
commit d9ae4e4ba0
3 changed files with 403 additions and 393 deletions

View File

@ -1,390 +1,390 @@
class RepositoriesController < ApplicationController class RepositoriesController < ApplicationController
include RepositoriesHelper include RepositoriesHelper
include ApplicationHelper include ApplicationHelper
include OperateProjectAbilityAble include OperateProjectAbilityAble
include Repository::LanguagesPercentagable include Repository::LanguagesPercentagable
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror] before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
before_action :require_profile_completed, only: [:create_file] before_action :require_profile_completed, only: [:create_file]
before_action :load_repository before_action :load_repository
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive] before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror] before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
before_action :get_ref, only: %i[entries sub_entries top_counts file archive] before_action :get_ref, only: %i[entries sub_entries top_counts file archive]
before_action :get_latest_commit, only: %i[entries sub_entries top_counts] before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
before_action :get_statistics, only: %i[top_counts] before_action :get_statistics, only: %i[top_counts]
def files def files
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token) result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
render json: result render json: result
end end
# 新版项目详情 # 新版项目详情
def detail def detail
@user = current_user @user = current_user
@result = Repositories::DetailService.call(@owner, @repository, @user) @result = Repositories::DetailService.call(@owner, @repository, @user)
@project_fork_id = @project.try(:forked_from_project_id) @project_fork_id = @project.try(:forked_from_project_id)
if @project_fork_id.present? if @project_fork_id.present?
@fork_project = Project.find_by(id: @project_fork_id) @fork_project = Project.find_by(id: @project_fork_id)
@fork_project_user = @fork_project.owner @fork_project_user = @fork_project.owner
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception(e.message) tip_exception(e.message)
end end
def show def show
@user = current_user @user = current_user
@repo = @project.repository @repo = @project.repository
@result = @project.forge? ? Gitea::Repository::GetService.new(@owner, @project.identifier).call : nil @result = @project.forge? ? Gitea::Repository::GetService.new(@owner, @project.identifier).call : nil
@project_fork_id = @project.try(:forked_from_project_id) @project_fork_id = @project.try(:forked_from_project_id)
if @project_fork_id.present? if @project_fork_id.present?
@fork_project = Project.find_by(id: @project_fork_id) @fork_project = Project.find_by(id: @project_fork_id)
@fork_project_user = @fork_project.owner @fork_project_user = @fork_project.owner
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception(e.message) tip_exception(e.message)
end end
def entries def entries
@project.increment!(:visits) @project.increment!(:visits)
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id) CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
if @project.educoder? if @project.educoder?
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name) @entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
else else
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call @entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : [] @entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
end end
end end
def top_counts def top_counts
@result = @project.educoder? ? nil : Gitea::Repository::GetService.new(@project.owner, @project.identifier).call @result = @project.educoder? ? nil : Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
end end
def sub_entries def sub_entries
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
if @project.educoder? if @project.educoder?
if params[:type] === 'file' if params[:type] === 'file'
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri) @sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
logger.info "######### sub_entries: #{@sub_entries}" logger.info "######### sub_entries: #{@sub_entries}"
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1 return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
tmp_entries = { tmp_entries = {
"content" => @sub_entries['data']['content'], "content" => @sub_entries['data']['content'],
"type" => "blob" "type" => "blob"
} }
@sub_entries = { @sub_entries = {
"trees"=>tmp_entries, "trees"=>tmp_entries,
"commits" => [{}] "commits" => [{}]
} }
else else
begin begin
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
if @sub_entries.blank? || @sub_entries['status'].to_i === -1 if @sub_entries.blank? || @sub_entries['status'].to_i === -1
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri) @sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1 return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
tmp_entries = { tmp_entries = {
"content" => @sub_entries['data']['content'], "content" => @sub_entries['data']['content'],
"type" => "blob" "type" => "blob"
} }
@sub_entries = { @sub_entries = {
"trees"=>tmp_entries, "trees"=>tmp_entries,
"commits" => [{}] "commits" => [{}]
} }
end end
rescue rescue
return render_error('该文件暂未开放,敬请期待.') return render_error('该文件暂未开放,敬请期待.')
end end
end end
else else
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref) interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
if interactor.success? if interactor.success?
result = interactor.result result = interactor.result
@sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result @sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result
else else
render_error(interactor.error) render_error(interactor.error)
end end
end end
end end
def commits def commits
if @project.educoder? if @project.educoder?
@commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name) @commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
else else
if params[:filepath].present? if params[:filepath].present?
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
else else
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
end end
end end
end end
def commits_slice def commits_slice
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier, @hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token) sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
end end
def commit def commit
@sha = params[:sha] @sha = params[:sha]
if @project.educoder? if @project.educoder?
return render_error('暂未开放,敬请期待.') return render_error('暂未开放,敬请期待.')
else else
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true}) @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
end end
end end
def tags def tags
result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]})
@tags = result.is_a?(Hash) && result.key?(:status) ? [] : result @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result
end end
def contributors def contributors
if params[:filepath].present? || @project.educoder? if params[:filepath].present? || @project.educoder?
@contributors = [] @contributors = []
else else
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result @contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
end end
rescue rescue
@contributors = [] @contributors = []
end end
def edit def edit
return render_forbidden if !@project.manager?(current_user) && !current_user.admin? return render_forbidden if !@project.manager?(current_user) && !current_user.admin?
end end
def create_file def create_file
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
if interactor.success? if interactor.success?
@file = interactor.result @file = interactor.result
# create_new_pr(params) # create_new_pr(params)
#如果是更新流水线文件 #如果是更新流水线文件
if params[:pipeline_id] if params[:pipeline_id]
update_pipeline(params[:pipeline_id]) update_pipeline(params[:pipeline_id])
end end
else else
render_error(interactor.error) render_error(interactor.error)
end end
end end
def update_pipeline(pipeline_id) def update_pipeline(pipeline_id)
pipeline = Ci::Pipeline.find(pipeline_id) pipeline = Ci::Pipeline.find(pipeline_id)
if pipeline if pipeline
pipeline.update!(sync: 1) pipeline.update!(sync: 1)
end end
end end
def update_file def update_file
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier)) interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
if interactor.success? if interactor.success?
@file = interactor.result @file = interactor.result
# TODO: 是否创建pr # TODO: 是否创建pr
# create_new_pr(params) # create_new_pr(params)
render_result(1, "更新成功") render_result(1, "更新成功")
else else
render_error(interactor.error) render_error(interactor.error)
end end
end end
def delete_file def delete_file
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier)) interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier))
if interactor.success? if interactor.success?
@file = interactor.result @file = interactor.result
render_result(1, "文件删除成功") render_result(1, "文件删除成功")
else else
render_error(interactor.error) render_error(interactor.error)
end end
end end
def repo_hook def repo_hook
end end
def sync_mirror def sync_mirror
return render_error("正在镜像中..") if @repository.mirror.waiting? return render_error("正在镜像中..") if @repository.mirror.waiting?
@repository.sync_mirror! @repository.sync_mirror!
SyncMirroredRepositoryJob.perform_later(@repository.id, current_user.id) SyncMirroredRepositoryJob.perform_later(@repository.id, current_user.id)
render_ok render_ok
end end
def readme def readme
if params[:filepath].present? if params[:filepath].present?
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token) result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token)
else else
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
end end
@path = Gitea.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @path = Gitea.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
@readme = result[:status] === :success ? result[:body] : nil @readme = result[:status] === :success ? result[:body] : nil
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path) @readme['content'] = decode64_readme_content(@readme, @owner, @repository, params[:ref], @path)
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha")
rescue rescue
render json: nil render json: nil
end end
def languages def languages
if @project.educoder? if @project.educoder?
render json: {} render json: {}
else else
render json: languages_precentagable render json: languages_precentagable
end end
end end
def archive def archive
domain = Gitea.gitea_config[:domain] domain = Gitea.gitea_config[:domain]
api_url = Gitea.gitea_config[:base_url] api_url = Gitea.gitea_config[:base_url]
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}" archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
file_path = [domain, api_url, archive_url].join file_path = [domain, api_url, archive_url].join
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden? file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
return render_not_found if !request.format.zip? && !request.format.gzip? return render_not_found if !request.format.zip? && !request.format.gzip?
redirect_to file_path redirect_to file_path
end end
def raw def raw
domain = Gitea.gitea_config[:domain] domain = Gitea.gitea_config[:domain]
api_url = Gitea.gitea_config[:base_url] api_url = Gitea.gitea_config[:base_url]
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}" url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}"
file_path = [domain, api_url, url].join file_path = [domain, api_url, url].join
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
redirect_to file_path redirect_to file_path
end end
private private
def find_project def find_project
@project = Project.find params[:id] @project = Project.find params[:id]
render_not_found("未找到相关的仓库") unless @project render_not_found("未找到相关的仓库") unless @project
end end
def find_project_with_includes def find_project_with_includes
@project = Project.includes(:repository, :owner, :watchers, :praise_treads).find params[:id] @project = Project.includes(:repository, :owner, :watchers, :praise_treads).find params[:id]
end end
def authorizate! def authorizate!
return if current_user && current_user.admin? return if current_user && current_user.admin?
if @project.repository.hidden? && !@project.member?(current_user) if @project.repository.hidden? && !@project.member?(current_user)
render_forbidden render_forbidden
end end
end end
# TODO 获取最新commit信息 # TODO 获取最新commit信息
def project_commits def project_commits
if params[:filepath].present? if params[:filepath].present?
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri, Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
else else
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
end end
end end
def get_statistics def get_statistics
@branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size @branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
@tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size @tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
end end
def get_ref def get_ref
@ref = params[:ref] || @project&.default_branch @ref = params[:ref] || @project&.default_branch
end end
def get_latest_commit def get_latest_commit
latest_commit = @project.educoder? ? nil : project_commits latest_commit = @project.educoder? ? nil : project_commits
@latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil @latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil
@commits_count = latest_commit.present? ? latest_commit[:total_count] : 0 @commits_count = latest_commit.present? ? latest_commit[:total_count] : 0
end end
def content_params def content_params
{ {
filepath: params[:filepath], filepath: params[:filepath],
branch: params[:branch], branch: params[:branch],
new_branch: params[:new_branch], new_branch: params[:new_branch],
content: params[:content], content: params[:content],
message: params[:message], message: params[:message],
committer: { committer: {
email: current_user.mail, email: current_user.mail,
name: current_user.login name: current_user.login
}, },
identifier: @project.identifier identifier: @project.identifier
} }
end end
def hook_params(hook_type, params) def hook_params(hook_type, params)
# if hook_type == "push" # if hook_type == "push"
# # TODO hook返回的记录中暂时没有文件代码数量的增减暂时根据 commits数量来计算 # # TODO hook返回的记录中暂时没有文件代码数量的增减暂时根据 commits数量来计算
# uploadPushInfo = { # uploadPushInfo = {
# "sha": params["commits"].present? ? params["commits"].last : "", # "sha": params["commits"].present? ? params["commits"].last : "",
# "branch": params["ref"].to_s.split("/").last, # "branch": params["ref"].to_s.split("/").last,
# "modification_lines": params["commits"].length # "modification_lines": params["commits"].length
# } # }
# elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作 # elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
# uploadPushInfo = { # uploadPushInfo = {
# "branch": params["base"]["ref"].to_s.split("/").last, # "branch": params["base"]["ref"].to_s.split("/").last,
# "sha": params["pull_request"]["merge_base"], # "sha": params["pull_request"]["merge_base"],
# "modification_lines": 1 #pull_request中没有commits数量 # "modification_lines": 1 #pull_request中没有commits数量
# } # }
# else # else
# uploadPushInfo = {} # uploadPushInfo = {}
# end # end
# uploadPushInfo # uploadPushInfo
end end
def create_new_pr(params) def create_new_pr(params)
if params[:new_branch].present? && params[:new_branch] != params[:branch] if params[:new_branch].present? && params[:new_branch] != params[:branch]
local_params = { local_params = {
title: params[:message], #标题 title: params[:message], #标题
body: params[:content], #内容 body: params[:content], #内容
head: params[:new_branch], #源分支 head: params[:new_branch], #源分支
base: params[:branch], #目标分支 base: params[:branch], #目标分支
milestone: 0 #里程碑,未与本地的里程碑关联 milestone: 0 #里程碑,未与本地的里程碑关联
} }
requests_params = local_params.merge({ requests_params = local_params.merge({
assignee: current_user.try(:login), assignee: current_user.try(:login),
assignees: [], assignees: [],
labels: [], labels: [],
due_date: Time.now due_date: Time.now
}) })
issue_params = { issue_params = {
author_id: current_user.id, author_id: current_user.id,
project_id: @project.id, project_id: @project.id,
subject: params[:message], subject: params[:message],
description: params[:content], description: params[:content],
assigned_to_id: nil, assigned_to_id: nil,
fixed_version_id: nil, fixed_version_id: nil,
issue_tags_value: nil, issue_tags_value: nil,
issue_classify: "pull_request", issue_classify: "pull_request",
issue_type: "1", issue_type: "1",
tracker_id: 2, tracker_id: 2,
status_id: 1, status_id: 1,
priority_id: params[:priority_id] || "2" priority_id: params[:priority_id] || "2"
} }
@pull_issue = Issue.new(issue_params) @pull_issue = Issue.new(issue_params)
if @pull_issue.save! if @pull_issue.save!
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id)) local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
if local_requests.save if local_requests.save
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"]) if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
end end
end end
end end
end end
end end
end end

View File

@ -110,6 +110,15 @@ module RepositoriesHelper
date.to_time.strftime("%Y-%m-%d %H:%M") date.to_time.strftime("%Y-%m-%d %H:%M")
end end
def decode64_readme_content(entry, owner, repo, ref, path=nil)
if is_readme?(entry['type'], entry['name'])
path = URI.escape(entry['path']).to_s.downcase.gsub("/readme.md","")
readme_render_decode64_content(entry['content'], owner, repo, ref, path)
else
render_decode64_content(entry['content'])
end
end
def decode64_content(entry, owner, repo, ref, path=nil) def decode64_content(entry, owner, repo, ref, path=nil)
if is_readme?(entry['type'], entry['name']) if is_readme?(entry['type'], entry['name'])
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']

View File

@ -1,4 +1,5 @@
if @project.forge? if @project.forge?
is_dir = @sub_entries.is_a?(Array)
file_name = entry['name'] file_name = entry['name']
file_type = File.extname(file_name.to_s)[1..-1] file_type = File.extname(file_name.to_s)[1..-1]
direct_download = download_type(file_type) direct_download = download_type(file_type)
@ -9,16 +10,16 @@ if @project.forge?
json.type entry['type'] json.type entry['type']
json.size entry['size'] json.size entry['size']
json.content (direct_download || image_type) ? nil : decode64_content(entry, @owner, @repository, @ref, @path) json.content (direct_download || image_type || is_dir) ? nil : decode64_content(entry, @owner, @repository, @ref, @path)
json.target entry['target'] json.target entry['target']
download_url = download_url =
if image_type if image_type
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/') dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref)) is_dir ? "" : render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
else else
# entry['download_url'] # entry['download_url']
render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref)
end end
json.download_url download_url json.download_url download_url