Browse Source

ADD zip、tar url with entries api

tags/v1
Jasder 6 years ago
parent
commit
731ddd6fce
2 changed files with 7 additions and 4 deletions
  1. +5
    -4
      app/controllers/repositories_controller.rb
  2. +2
    -0
      app/views/repositories/entries.json.jbuilder

+ 5
- 4
app/controllers/repositories_controller.rb View File

@@ -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


+ 2
- 0
app/views/repositories/entries.json.jbuilder View File

@@ -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']


Loading…
Cancel
Save