From 74493512705ad50947f5a6e215506868b925db88 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Mon, 16 Nov 2020 15:34:16 +0800 Subject: [PATCH] FIX sub entries api return hash object when entries is file --- app/controllers/repositories_controller.rb | 7 ++----- app/services/gitea/repository/entries/get_service.rb | 4 +++- app/views/repositories/sub_entries.json.jbuilder | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 4df823131..c7f8539e5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -61,13 +61,10 @@ class RepositoriesController < ApplicationController @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) end else - interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: @ref) + interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref) if interactor.success? result = interactor.result - return @sub_entries = [] if result.is_a?(Hash) && result[:status] == -1 - - @sub_entries = result.is_a?(Array) ? result : [result] - @sub_entries = @sub_entries.sort_by{ |hash| hash['type'] } + @sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result else render_error(interactor.error) end diff --git a/app/services/gitea/repository/entries/get_service.rb b/app/services/gitea/repository/entries/get_service.rb index f0236a07d..f8ac27543 100644 --- a/app/services/gitea/repository/entries/get_service.rb +++ b/app/services/gitea/repository/entries/get_service.rb @@ -31,8 +31,10 @@ class Gitea::Repository::Entries::GetService < Gitea::ClientService case response.status when 200 body + when 404 + raise '你访问的文件不存在' else - {status: -1, message: "#{body['message']}"} + raise body['message'] end end end diff --git a/app/views/repositories/sub_entries.json.jbuilder b/app/views/repositories/sub_entries.json.jbuilder index 5d94f5d60..3276ed0dd 100644 --- a/app/views/repositories/sub_entries.json.jbuilder +++ b/app/views/repositories/sub_entries.json.jbuilder @@ -6,12 +6,11 @@ if @project.forge? json.nil! end end - #json.tags_count @tags_count - #json.branches_count @branches_count - #json.commits_count @commits_count json.entries do - json.array! @sub_entries do |entry| - json.partial! 'repositories/simple_entry', locals: { entry: entry } + if @sub_entries.is_a?(Array) + json.partial! 'repositories/simple_entry', collection: @sub_entries, as: :entry + elsif @sub_entries.is_a?(Hash) + json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries } end end end