From f3f2ea8ef03d3fcb9fbe8829db924ffe6ba70afa Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 8 Mar 2023 19:40:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=99=90=E5=88=B6=E9=A2=91?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 8 ++++---- class/core/mw.py | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 570239abb..16cda719c 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -663,14 +663,14 @@ class config_api: def getNotifyApi(self): # 获取 - data = mw.getNotifyData() + data = mw.getNotifyData(True) return mw.returnData(True, 'ok', data) def setNotifyApi(self): tag = request.form.get('tag', '').strip() data = request.form.get('data', '').strip() - cfg = mw.getNotifyData() + cfg = mw.getNotifyData(False) crypt_data = mw.enDoubleCrypt(tag, data) if tag in cfg: @@ -701,7 +701,7 @@ class config_api: tag = request.form.get('tag', '').strip() tag_enable = request.form.get('enable', '').strip() - data = mw.getNotifyData() + data = mw.getNotifyData(False) op_enable = True op_action = '开启' if tag_enable != 'true': @@ -908,7 +908,7 @@ class config_api: data['hook_global_static'] = [] # notiy config - notify_data = mw.getNotifyData() + notify_data = mw.getNotifyData(True) notify_tag_list = ['tgbot', 'email'] for tag in notify_tag_list: new_tag = 'notify_' + tag + '_enable' diff --git a/class/core/mw.py b/class/core/mw.py index 262f106b9..ad20ece0b 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -82,6 +82,10 @@ def getPanelDataDir(): return getRunDir() + '/data' +def getPanelTmp(): + return getRunDir() + '/tmp' + + def getServerDir(): return getRootDir() + '/server' @@ -1677,16 +1681,18 @@ def getNotifyPath(): return path -def getNotifyData(): +def getNotifyData(is_parse=False): initNotifyConfig() notify_file = getNotifyPath() notify_data = readFile(notify_file) data = json.loads(notify_data) - tag_list = ['tgbot'] - for t in tag_list: - if t in data and 'cfg' in data[t]: - data[t]['data'] = json.loads(deDoubleCrypt(t, data[t]['cfg'])) + + if is_parse: + tag_list = ['tgbot'] + for t in tag_list: + if t in data and 'cfg' in data[t]: + data[t]['data'] = json.loads(deDoubleCrypt(t, data[t]['cfg'])) return data @@ -1729,7 +1735,27 @@ def tgbotNotifyTest(app_token, chat_id): return False -def notifyMessage(msg): +def notifyMessage(msg, stype='common', trigger_time=300, is_write_log=True): + + lock_file = getPanelTmp() + '/notify_lock.json' + if not os.path.exists(lock_file): + writeFile(lock_file, '{}') + + lock_data = json.loads(readFile(lock_file)) + if stype in lock_data: + diff_time = time.time() - lock_data[stype]['do_time'] + if diff_time >= trigger_time: + lock_data[stype]['do_time'] = time.time() + else: + return False + else: + lock_data[stype] = {'do_time': time.time()} + + writeFile(lock_file, json.dumps(lock_data)) + + if is_write_log: + writeLog("通知管理[" + stype + "]", msg) + data = getNotifyData() # tag_list = ['tgbot', 'email'] # tagbot