diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e327554a7..5fb7b7681 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -7,10 +7,17 @@ class RepositoriesController < ApplicationController before_action :load_repository before_action :authorizate!, except: [:sync_mirror, :tags, :commit] before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror] - before_action :get_ref, only: %i[entries sub_entries top_counts] + before_action :get_ref, only: %i[entries sub_entries top_counts file] before_action :get_latest_commit, only: %i[entries sub_entries top_counts] before_action :get_statistics, only: %i[top_counts] + + + def files + result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@project.owner, @project.identifier, @ref) + render json: result + end + # 新版项目详情 def detail @user = current_user diff --git a/app/services/gitea/repository/files/get_service.rb b/app/services/gitea/repository/files/get_service.rb new file mode 100644 index 000000000..e5b96e7ba --- /dev/null +++ b/app/services/gitea/repository/files/get_service.rb @@ -0,0 +1,25 @@ +class Gitea::Repository::Files::GetService < Gitea::ClientService + attr_reader :owner, :repo_name, :ref, :q, :token + + def initialize(owner, repo_name, ref, q=nil, token=nil) + @owner = owner + @repo_name = repo_name + @ref = ref + @q = q + @token = token + end + + def call + response = get(url, params) + render_status(response) + end + + private + def params + Hash.new.merge(token: token, ref: ref, q: q) + end + + def url + "/repos/#{owner.login}/#{repo_name}/find" + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4f350314b..9aed0ca5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -378,8 +378,9 @@ Rails.application.routes.draw do end end - resource :repositories, path: '/', only: [:show, :create, :edit] do + resource :repositories, path: '/', only: [:show, :create, :edit] do member do + get :files get :detail get :archive get :top_counts