保存现有功能 增加域名和添加时间关联
This commit is contained in:
22
app/utils.py
22
app/utils.py
@@ -260,10 +260,13 @@ def extract_code_from_body(body):
|
||||
|
||||
|
||||
def add_allowed_domain(domain):
|
||||
"""添加允许的域名"""
|
||||
"""添加允许的域名并记录添加时间"""
|
||||
try:
|
||||
timestamp = datetime.now().isoformat()
|
||||
redis_client.sadd('allowed_domains', domain)
|
||||
logger.info(f'Added allowed domain: {domain}')
|
||||
redis_client.hset(f'domain:{domain}', 'status', 'allowed') # 新增状态键
|
||||
redis_client.hset(f'domain_time:{domain}', 'added_at', timestamp) # 记录添加时间
|
||||
logger.info(f'Added allowed domain: {domain} at {timestamp}')
|
||||
except Exception as e:
|
||||
logger.error(f'Error adding allowed domain: {e}')
|
||||
|
||||
@@ -285,3 +288,18 @@ def get_allowed_domains():
|
||||
except Exception as e:
|
||||
logger.error(f'Error fetching allowed domains: {e}')
|
||||
return []
|
||||
|
||||
|
||||
def get_allowed_domains_with_time():
|
||||
"""获取当前允许的域名及其添加时间"""
|
||||
try:
|
||||
domains = redis_client.smembers('allowed_domains')
|
||||
domain_info = {}
|
||||
for domain in domains:
|
||||
domain = domain.decode()
|
||||
added_at = redis_client.hget(f'domain_time:{domain}', 'added_at')
|
||||
domain_info[domain] = added_at.decode() if added_at else None
|
||||
return domain_info
|
||||
except Exception as e:
|
||||
logger.error(f'Error fetching allowed domains with time: {e}')
|
||||
return {}
|
||||
Reference in New Issue
Block a user