huanx
This commit is contained in:
21
app/utils.py
21
app/utils.py
@@ -260,12 +260,10 @@ def extract_code_from_body(body):
|
|||||||
|
|
||||||
|
|
||||||
def add_allowed_domain(domain):
|
def add_allowed_domain(domain):
|
||||||
"""添加允许的域名并记录创建时间"""
|
"""添加允许的域名"""
|
||||||
try:
|
try:
|
||||||
timestamp = datetime.now().isoformat()
|
redis_client.sadd('allowed_domains', domain)
|
||||||
redis_client.rpush('allowed_domains_list', domain) # 添加到列表
|
logger.info(f'Added allowed domain: {domain}')
|
||||||
redis_client.hset(f'domain:{domain}', 'created_at', timestamp) # 记录创建时间
|
|
||||||
logger.info(f'Added allowed domain: {domain} with timestamp: {timestamp}')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error adding allowed domain: {e}')
|
logger.error(f'Error adding allowed domain: {e}')
|
||||||
|
|
||||||
@@ -280,15 +278,10 @@ def remove_allowed_domain(domain):
|
|||||||
|
|
||||||
|
|
||||||
def get_allowed_domains():
|
def get_allowed_domains():
|
||||||
"""获取当前允许的域名及其创建时间"""
|
"""获取当前允许的域名列表"""
|
||||||
try:
|
try:
|
||||||
domains = redis_client.lrange('allowed_domains_list', 0, -1)
|
domains = redis_client.smembers('allowed_domains')
|
||||||
domain_info = {}
|
return [domain.decode() for domain in domains]
|
||||||
for domain in domains:
|
|
||||||
domain = domain.decode()
|
|
||||||
created_at = redis_client.hget(f'domain:{domain}', 'created_at')
|
|
||||||
domain_info[domain] = created_at.decode() if created_at else None
|
|
||||||
return domain_info
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error fetching allowed domains: {e}')
|
logger.error(f'Error fetching allowed domains: {e}')
|
||||||
return {}
|
return []
|
||||||
Reference in New Issue
Block a user