From ca8c9eb7170ea727658c0dcec12f65130545a98f Mon Sep 17 00:00:00 2001 From: pengshiyu <1940607002@qq.com> Date: Tue, 4 Apr 2023 14:04:28 +0800 Subject: [PATCH] v1.2.0 --- CHANGELOG.md | 5 +++ README.md | 4 +-- domain_admin/api/domain_api.py | 39 +++++++++++++++++++-- domain_admin/api/group_api.py | 25 +++++++------ domain_admin/router/api_map.py | 3 +- domain_admin/service/domain_service.py | 22 +++++++++--- domain_admin/service/global_data_service.py | 22 ++++++++++++ domain_admin/version.py | 2 +- 8 files changed, 100 insertions(+), 22 deletions(-) create mode 100644 domain_admin/service/global_data_service.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f4cdd6dd6..60e1c764e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 更新日志 +- v1.2.0(2023-04-04) + - 新增:支持域名分组 + - 优化:异步操作的前端状态显示 + - 优化:优化前端域名列表字段显示 + - v1.1.10(2023-04-03) - 修复:部分域名剩余天数检测失败的问题 - 优化:查询域名之前进行域名优化处理,减少查询请求 diff --git a/README.md b/README.md index bf7506fc60..010800c4a8 100644 --- a/README.md +++ b/README.md @@ -291,13 +291,13 @@ sqlite> .quit 开发计划 - `已完成` 支持企业微信通知 -- 支持域名分组 +- `已完成` 支持域名分组 - 增加理员权限,权限分级:root 管理员 普通用户 - `已完成` 解决批量导入超时问题,支持1000条数据导入 - `已完成` 支持域名备注 - `已完成` 支持域名到期数据 - `已完成` webhook支持变量 -- 异步操作的前端状态显示 +- `已完成` 异步操作的前端状态显示 证书测试:[https://badssl.com/](https://badssl.com/) diff --git a/domain_admin/api/domain_api.py b/domain_admin/api/domain_api.py index 6efdf1ae47..ec5bd8d921 100644 --- a/domain_admin/api/domain_api.py +++ b/domain_admin/api/domain_api.py @@ -5,7 +5,7 @@ from domain_admin.model.domain_model import DomainModel from domain_admin.model.group_model import GroupModel -from domain_admin.service import domain_service +from domain_admin.service import domain_service, global_data_service from domain_admin.service import file_service from domain_admin.service import async_task_service from domain_admin.utils import datetime_util @@ -136,7 +136,7 @@ def get_domain_list(): ] ), lst)) - lst = model_util.list_with_relation_one(lst, 'group', GroupModel) + # lst = model_util.list_with_relation_one(lst, 'group', GroupModel) return { 'list': lst, @@ -187,9 +187,41 @@ def update_all_domain_cert_info_of_user(): current_user_id = g.user_id # domain_service.update_all_domain_cert_info_of_user(current_user_id) # 异步更新 + key = f'update_domain_status:{current_user_id}' + global_data_service.set_value(key, True) async_task_service.submit_task(fn=domain_service.update_all_domain_cert_info_of_user, user_id=current_user_id) +def get_update_domain_status_of_user(): + """ + 获取域名信息更新状态 + true:正在更新 + false:更新完毕 + :return: + """ + current_user_id = g.user_id + key = f'update_domain_status:{current_user_id}' + + return { + 'status': global_data_service.get_value(key) + } + + +def get_check_domain_status_of_user(): + """ + 获取证书检查状态 + true:正在更新 + false:更新完毕 + :return: + """ + current_user_id = g.user_id + key = f'check_domain_status:{current_user_id}' + + return { + 'status': global_data_service.get_value(key) + } + + def update_domain_cert_info_by_id(): """ 更新域名证书信息 @@ -221,6 +253,9 @@ def check_domain_cert(): """ current_user_id = g.user_id + key = f'check_domain_status:{current_user_id}' + global_data_service.set_value(key, True) + # # 先更新,再检查 # domain_service.update_all_domain_cert_info_of_user(current_user_id) # diff --git a/domain_admin/api/group_api.py b/domain_admin/api/group_api.py index 67b79dbe8f..dd5619c133 100644 --- a/domain_admin/api/group_api.py +++ b/domain_admin/api/group_api.py @@ -32,11 +32,10 @@ def update_group_by_id(): current_user_id = g.user_id group_id = request.json['id'] + name = request.json.get('name') group_service.check_group_permission(group_id, current_user_id) - name = request.json.get('name') - GroupModel.update( name=name, ).where( @@ -63,21 +62,25 @@ def get_group_list(): 获取域名列表 :return: """ - # page = request.json.get('page', 1) - # size = request.json.get('size', 10) + page = request.json.get('page', 1) + size = request.json.get('size', 10) + keyword = request.json.get('keyword') current_user_id = g.user_id - lst = GroupModel.select().where( + query = GroupModel.select().where( GroupModel.user_id == current_user_id - ).order_by( - GroupModel.create_time.asc(), - GroupModel.id.asc() ) - total = GroupModel.select().where( - GroupModel.user_id == current_user_id - ).count() + if keyword: + query = query.where(GroupModel.name.contains(keyword)) + + total = query.count() + + lst = query.order_by( + GroupModel.create_time.asc(), + GroupModel.id.asc() + ).paginate(page, size) return { 'list': lst, diff --git a/domain_admin/router/api_map.py b/domain_admin/router/api_map.py index 4b2a2c9be3..c0ea7e47c1 100644 --- a/domain_admin/router/api_map.py +++ b/domain_admin/router/api_map.py @@ -31,6 +31,8 @@ "/api/checkDomainCert": domain_api.check_domain_cert, "/api/importDomainFromFile": domain_api.import_domain_from_file, "/api/getAllDomainListOfUser": domain_api.get_all_domain_list_of_user, + "/api/getUpdateDomainStatusOfUser": domain_api.get_update_domain_status_of_user, + "/api/getCheckDomainStatusOfUser": domain_api.get_check_domain_status_of_user, # 分组管理 "/api/addGroup": group_api.add_group, @@ -58,7 +60,6 @@ '/api/updateUserStatus': user_api.update_user_status, '/api/deleteUser': user_api.delete_user, - # 获取ip信息 '/api/getIpInfo': ip_api.get_ip_info, diff --git a/domain_admin/service/domain_service.py b/domain_admin/service/domain_service.py index 3381805c22..b3e1db292e 100644 --- a/domain_admin/service/domain_service.py +++ b/domain_admin/service/domain_service.py @@ -11,7 +11,7 @@ from domain_admin.model.domain_model import DomainModel from domain_admin.model.log_scheduler_model import LogSchedulerModel from domain_admin.model.user_model import UserModel -from domain_admin.service import email_service, render_service +from domain_admin.service import email_service, render_service, global_data_service from domain_admin.service import file_service from domain_admin.service import notify_service from domain_admin.service import system_service @@ -47,16 +47,17 @@ def add_domain(data): return row -def update_domain_cert_info(row, cache=None): +def update_domain_cert_info(row): """ 更新域名和证书信息 + :param cache: :param row: :return: """ logger.info('update_domain_cert_info: %s', row.domain) # 获取域名信息 - domain_info = get_domain_info(row.domain, cache) + domain_info = get_domain_info(row.domain) # 获取证书信息 cert_info = get_cert_info(row.domain) @@ -113,7 +114,7 @@ def get_cert_info(domain: str): } -def get_domain_info(domain: str, cache=None): +def get_domain_info(domain: str): """ 获取域名注册信息 :param domain: 域名 @@ -121,6 +122,8 @@ def get_domain_info(domain: str, cache=None): :return: """ + cache = global_data_service.get_value('update_domain_list_info_cache') + now = datetime.now() # 获取域名信息 @@ -173,13 +176,16 @@ def update_domain_list_info(rows): """ # 增加缓存,提升查询效率 cache = {} + global_data_service.set_value('update_domain_list_info_cache', cache) for row in rows: - update_domain_cert_info(row, cache) + update_domain_cert_info(row) # bugfix: ConnectionResetError: [Errno 104] Connection reset by peer # 请求过于频繁 time.sleep(0.5) + global_data_service.remove_value('update_domain_list_info_cache') + def update_all_domain_cert_info_of_user(user_id): """ @@ -192,6 +198,9 @@ def update_all_domain_cert_info_of_user(user_id): update_domain_list_info(lst) + key = f'update_domain_status:{user_id}' + global_data_service.set_value(key, False) + def get_domain_info_list(user_id=None): query = DomainModel.select() @@ -420,3 +429,6 @@ def update_and_check_domain_cert(user_id): update_all_domain_cert_info_of_user(user_id) check_domain_cert(user_id) + + key = f'check_domain_status:{user_id}' + global_data_service.set_value(key, False) diff --git a/domain_admin/service/global_data_service.py b/domain_admin/service/global_data_service.py new file mode 100644 index 0000000000..699572b09f --- /dev/null +++ b/domain_admin/service/global_data_service.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +""" +@File : global_data_service.py +@Date : 2023-04-04 + +APP全局数据 +""" + +GLOBAL_DATA = {} + + +def get_value(key): + return GLOBAL_DATA.get(key) + + +def set_value(key, value): + GLOBAL_DATA[key] = value + + +def remove_value(key): + if key in GLOBAL_DATA: + GLOBAL_DATA.pop(key) diff --git a/domain_admin/version.py b/domain_admin/version.py index 89cb9957b6..2db6a8d37f 100755 --- a/domain_admin/version.py +++ b/domain_admin/version.py @@ -2,4 +2,4 @@ """ 版本号 """ -VERSION = '1.1.10' +VERSION = '1.2.0'