Browse Source

raw api limit request.path

pull/348/head
xxq250 1 year ago
parent
commit
ae6400a06d
2 changed files with 14 additions and 0 deletions
  1. +13
    -0
      app/controllers/application_controller.rb
  2. +1
    -0
      app/controllers/repositories_controller.rb

+ 13
- 0
app/controllers/application_controller.rb View File

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

+ 1
- 0
app/controllers/repositories_controller.rb View File

@@ -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…
Cancel
Save