Fix #5168: Disable rate limits on testbooru/non-prod environments.
Add a `rate_limits_enabled?` config option for disabling rate limits.
This commit is contained in:
@@ -13,14 +13,16 @@
|
|||||||
class RateLimiter
|
class RateLimiter
|
||||||
class RateLimitError < StandardError; end
|
class RateLimitError < StandardError; end
|
||||||
|
|
||||||
attr_reader :action, :keys, :cost, :rate, :burst
|
attr_reader :action, :keys, :cost, :rate, :burst, :enabled
|
||||||
|
alias_method :enabled?, :enabled
|
||||||
|
|
||||||
def initialize(action, keys = ["*"], cost: 1, rate: 1, burst: 1)
|
def initialize(action, keys = ["*"], cost: 1, rate: 1, burst: 1, enabled: Danbooru.config.rate_limits_enabled?)
|
||||||
@action = action
|
@action = action
|
||||||
@keys = keys
|
@keys = keys
|
||||||
@cost = cost
|
@cost = cost
|
||||||
@rate = rate
|
@rate = rate
|
||||||
@burst = burst
|
@burst = burst
|
||||||
|
@enabled = enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a RateLimiter object for the given action. A RateLimiter usually has
|
# Create a RateLimiter object for the given action. A RateLimiter usually has
|
||||||
@@ -46,7 +48,7 @@ class RateLimiter
|
|||||||
|
|
||||||
# @return [Boolean] true if the action is limited for the user or their IP
|
# @return [Boolean] true if the action is limited for the user or their IP
|
||||||
def limited?
|
def limited?
|
||||||
rate_limits.any?(&:limited?)
|
enabled? && rate_limits.any?(&:limited?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options = {})
|
def as_json(options = {})
|
||||||
|
|||||||
@@ -372,6 +372,11 @@ module Danbooru
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Whether to enable API rate limits.
|
||||||
|
def rate_limits_enabled?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def stripe_secret_key
|
def stripe_secret_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user