fix: 更新检查后端限制4h请求一次
This commit is contained in:
@@ -118,20 +118,25 @@ class GlobalConfig(ConfigBase):
|
||||
|
||||
Data_UID = ConfigItem("Data", "UID", str(uuid.uuid4()), UUIDValidator())
|
||||
Data_LastStatisticsUpload = ConfigItem(
|
||||
"Data", "LastStatisticsUpload", "2000-01-01 00:00:00"
|
||||
"Data", "LastStatisticsUpload", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_LastStageUpdated = ConfigItem(
|
||||
"Data", "LastStageUpdated", "2000-01-01 00:00:00"
|
||||
"Data", "LastStageUpdated", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_StageTimeStamp = ConfigItem(
|
||||
"Data", "StageTimeStamp", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_StageTimeStamp = ConfigItem("Data", "StageTimeStamp", "2000-01-01 00:00:00")
|
||||
Data_Stage = ConfigItem("Data", "Stage", "{ }")
|
||||
Data_LastNoticeUpdated = ConfigItem(
|
||||
"Data", "LastNoticeUpdated", "2000-01-01 00:00:00"
|
||||
"Data", "LastNoticeUpdated", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_IfShowNotice = ConfigItem("Data", "IfShowNotice", True, BoolValidator())
|
||||
Data_Notice = ConfigItem("Data", "Notice", "{ }")
|
||||
Data_LastWebConfigUpdated = ConfigItem(
|
||||
"Data", "LastWebConfigUpdated", "2000-01-01 00:00:00"
|
||||
"Data", "LastWebConfigUpdated", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_LastCheckVersion = ConfigItem(
|
||||
"Data", "LastCheckVersion", "2000-01-01 00:00:00", DateTimeValidator()
|
||||
)
|
||||
Data_WebConfig = ConfigItem("Data", "WebConfig", "{ }")
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import json
|
||||
import uuid
|
||||
import win32com.client
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List, Any, Dict, Union, Optional
|
||||
|
||||
@@ -112,6 +113,27 @@ class UUIDValidator(ConfigValidator):
|
||||
return value if self.validate(value) else str(uuid.uuid4())
|
||||
|
||||
|
||||
class DateTimeValidator(ConfigValidator):
|
||||
|
||||
def validate(self, value: Any) -> bool:
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
try:
|
||||
datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def correct(self, value: Any) -> str:
|
||||
if not isinstance(value, str):
|
||||
return "2000-01-01 00:00:00"
|
||||
try:
|
||||
datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
|
||||
return value
|
||||
except ValueError:
|
||||
return "2000-01-01 00:00:00"
|
||||
|
||||
|
||||
class EncryptValidator(ConfigValidator):
|
||||
"""加密数据验证器"""
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import zipfile
|
||||
import requests
|
||||
import subprocess
|
||||
from packaging import version
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List, Dict, Optional
|
||||
from pathlib import Path
|
||||
|
||||
@@ -49,6 +50,23 @@ class _UpdateHandler:
|
||||
self, current_version: str
|
||||
) -> tuple[bool, str, Dict[str, List[str]]]:
|
||||
|
||||
if datetime.now() - timedelta(hours=4) < datetime.strptime(
|
||||
Config.get("Data", "LastCheckVersion"), "%Y-%m-%d %H:%M:%S"
|
||||
):
|
||||
logger.info("四小时内已进行过一次检查, 直接使用缓存的版本更新信息")
|
||||
return (
|
||||
(
|
||||
False
|
||||
if self.remote_version is None
|
||||
else bool(
|
||||
version.parse(self.remote_version)
|
||||
> version.parse(current_version)
|
||||
)
|
||||
),
|
||||
current_version if self.remote_version is None else self.remote_version,
|
||||
{},
|
||||
)
|
||||
|
||||
logger.info("开始检查更新")
|
||||
|
||||
response = requests.get(
|
||||
@@ -72,6 +90,9 @@ class _UpdateHandler:
|
||||
)
|
||||
|
||||
logger.success("获取版本信息成功")
|
||||
await Config.set(
|
||||
"Data", "LastCheckVersion", datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
)
|
||||
|
||||
remote_version = version_info["data"]["version_name"]
|
||||
self.remote_version = remote_version
|
||||
|
||||
Reference in New Issue
Block a user