diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ac8201c93..6d0867a0c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -6,7 +6,8 @@ class RepositoriesController < ApplicationController before_action :authorizate!, except: [:sync_mirror, :tags, :commit] before_action :find_repository_by_id, only: %i[commit sync_mirror tags] before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror] - before_action :get_latest_commit, only: %i[entries sub_entries] + before_action :get_ref, only: %i[entries sub_entries] + before_action :get_latest_commit, :get_ref, only: %i[entries sub_entries] def show @branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size @@ -27,13 +28,13 @@ class RepositoriesController < ApplicationController def entries @project.increment!(:visits) - @entries = Gitea::Repository::Entries::ListService.new(@project.owner, @project.identifier, ref: get_ref).call + @entries = Gitea::Repository::Entries::ListService.new(@project.owner, @project.identifier, ref: @ref).call @entries = @entries.sort_by{ |hash| hash['type'] } end def sub_entries file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) - interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: get_ref) + interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: @ref) if interactor.success? @sub_entries = interactor.result @sub_entries = [] << @sub_entries unless @sub_entries.is_a? Array @@ -137,7 +138,7 @@ class RepositoriesController < ApplicationController end def get_ref - params[:ref] || "master" + @ref = params[:ref] || "master" end def content_params diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 43275f3fa..6017ab226 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -5,6 +5,8 @@ json.last_commit do json.nil! end end +json.zip_url render_zip_url(@project, @ref) +json.tar_url render_tar_url(@project, @ref) json.entries do json.array! @entries do |entry| json.name entry['name']