mirror of
https://github.com/docusealco/docuseal
synced 2026-11-07 07:22:32 -05:00
add rate limit
This commit is contained in:
1 parent
265b668cb4
commit
749722a9df
4 files changed
+33
No files matched your search
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RateLimit
|
||||
LimitApproached = Class.new(StandardError)
|
||||
|
||||
STORE = ActiveSupport::Cache::MemoryStore.new
|
||||
|
||||
module_function
|
||||
|
||||
def call(key, limit:, ttl:, enabled: Docuseal.multitenant?)
|
||||
return true unless enabled
|
||||
|
||||
value = STORE.increment(key, 1, expires_in: ttl)
|
||||
|
||||
raise LimitApproached if value > limit
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user