mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-02 10:42:36 +08:00
Feat:update webhook component (#11739)
### What problem does this PR solve? issue: https://github.com/infiniflow/ragflow/issues/10427 https://github.com/infiniflow/ragflow/issues/8115 change: - Support for Multiple HTTP Methods (POST / GET / PUT / PATCH / DELETE / HEAD) - Security Validation 1. max_body_size 2. IP whitelist 3. rate limit 4. token / basic / jwt authentication - File Upload Support - Unified Content-Type Handling - Full Schema-Based Extraction & Type Validation - Two Execution Modes: Immediately / Streaming ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -59,6 +59,7 @@ class RedisMsg:
|
||||
@singleton
|
||||
class RedisDB:
|
||||
lua_delete_if_equal = None
|
||||
lua_token_bucket = None
|
||||
LUA_DELETE_IF_EQUAL_SCRIPT = """
|
||||
local current_value = redis.call('get', KEYS[1])
|
||||
if current_value and current_value == ARGV[1] then
|
||||
@ -68,6 +69,47 @@ class RedisDB:
|
||||
return 0
|
||||
"""
|
||||
|
||||
LUA_TOKEN_BUCKET_SCRIPT = """
|
||||
-- KEYS[1] = rate limit key
|
||||
-- ARGV[1] = capacity
|
||||
-- ARGV[2] = rate
|
||||
-- ARGV[3] = now
|
||||
-- ARGV[4] = cost
|
||||
|
||||
local key = KEYS[1]
|
||||
local capacity = tonumber(ARGV[1])
|
||||
local rate = tonumber(ARGV[2])
|
||||
local now = tonumber(ARGV[3])
|
||||
local cost = tonumber(ARGV[4])
|
||||
|
||||
local data = redis.call("HMGET", key, "tokens", "timestamp")
|
||||
local tokens = tonumber(data[1])
|
||||
local last_ts = tonumber(data[2])
|
||||
|
||||
if tokens == nil then
|
||||
tokens = capacity
|
||||
last_ts = now
|
||||
end
|
||||
|
||||
local delta = math.max(0, now - last_ts)
|
||||
tokens = math.min(capacity, tokens + delta * rate)
|
||||
|
||||
if tokens < cost then
|
||||
return {0, tokens}
|
||||
end
|
||||
|
||||
tokens = tokens - cost
|
||||
|
||||
redis.call("HMSET", key,
|
||||
"tokens", tokens,
|
||||
"timestamp", now
|
||||
)
|
||||
|
||||
redis.call("EXPIRE", key, math.ceil(capacity / rate * 2))
|
||||
|
||||
return {1, tokens}
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.REDIS = None
|
||||
self.config = REDIS
|
||||
@ -77,6 +119,7 @@ class RedisDB:
|
||||
cls = self.__class__
|
||||
client = self.REDIS
|
||||
cls.lua_delete_if_equal = client.register_script(cls.LUA_DELETE_IF_EQUAL_SCRIPT)
|
||||
cls.lua_token_bucket = client.register_script(cls.LUA_TOKEN_BUCKET_SCRIPT)
|
||||
|
||||
def __open__(self):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user