raw api limit request.path
This commit is contained in:
parent
f8b601bc9f
commit
5a1e942d1c
|
@ -1202,4 +1202,17 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def request_raw_limit
|
||||||
|
record_count = Rails.cache.read("request/#{request.path}/#{Time.now.strftime('%Y%m%d%H')}}")
|
||||||
|
if record_count.present?
|
||||||
|
record_count = record_count + 1
|
||||||
|
else
|
||||||
|
record_count = 1
|
||||||
|
end
|
||||||
|
Rails.logger.info("请求太快,请稍后再试。#{request.path}") if record_count > 1000
|
||||||
|
tip_exception("请求太快,请稍后再试。") if record_count > 1000
|
||||||
|
|
||||||
|
Rails.cache.write("request/#{request.path}/#{Time.now.strftime('%Y%m%d%H')}}", record_count, expires_in: 1.hour)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ class RepositoriesController < ApplicationController
|
||||||
before_action :get_statistics, only: %i[top_counts]
|
before_action :get_statistics, only: %i[top_counts]
|
||||||
before_action :require_referer, only: [:raw]
|
before_action :require_referer, only: [:raw]
|
||||||
before_action :request_limit, only: [:raw]
|
before_action :request_limit, only: [:raw]
|
||||||
|
before_action :request_raw_limit, only: [:raw]
|
||||||
|
|
||||||
def files
|
def files
|
||||||
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
|
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
|
||||||
|
|
Loading…
Reference in New Issue