raw api limit
This commit is contained in:
parent
144860fd2f
commit
7d1688c3dd
|
@ -1184,7 +1184,21 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
tip_exception("请求太快,请稍后再试。") if record_count > 100
|
||||
|
||||
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 1.minute)
|
||||
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 10.minute)
|
||||
end
|
||||
|
||||
def check_batch_requests
|
||||
check_key = "request.remote_ip:#{request.remote_ip}"
|
||||
result = Rails.cache.read(check_key)
|
||||
if result.present?
|
||||
if result.to_i > 100
|
||||
tip_exception(401, '暂时无法请求,请稍后再试')
|
||||
else
|
||||
Rails.cache.write(check_key, result.to_i + 1)
|
||||
end
|
||||
else
|
||||
Rails.cache.write(check_key, 1, expires_in: 1.hour)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ class RepositoriesController < ApplicationController
|
|||
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
||||
before_action :get_statistics, only: %i[top_counts]
|
||||
before_action :require_referer, only: [:raw]
|
||||
before_action :request_limit, only: [:raw]
|
||||
|
||||
def files
|
||||
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)
|
||||
|
|
Loading…
Reference in New Issue