From 0d64768e4b1e4f9b145a2157354de1559d2fd60a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Dec 2021 09:37:28 +0800 Subject: [PATCH] fix: educoder file visit delay --- app/controllers/repositories_controller.rb | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f3fffd6e1..94ee26a29 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -80,18 +80,22 @@ class RepositoriesController < ApplicationController "commits" => [{}] } else - @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) - if @sub_entries.blank? - @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 - tmp_entries = [{ - "content" => @sub_entries['data']['content'], - "type" => "blob" - }] - @sub_entries = { - "trees"=>tmp_entries, - "commits" => [{}] - } + begin + @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) + if @sub_entries.blank? + @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 + tmp_entries = [{ + "content" => @sub_entries['data']['content'], + "type" => "blob" + }] + @sub_entries = { + "trees"=>tmp_entries, + "commits" => [{}] + } + end + rescue + return render_error('该文件暂未开放,敬请期待.') end end else @@ -129,8 +133,7 @@ class RepositoriesController < ApplicationController def commit @sha = params[:sha] if @project.educoder? - @commit = {} - @commit_diff ={} + return render_error('暂未开放,敬请期待.') else @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})