From df85873726fbc1e4ad872a0c0294faff8867306f Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:04:09 +0800 Subject: [PATCH 1/4] feat(ua): add `cup_arch` , `USER_AGENT` value add `cup_arch` --- app/core/config.py | 4 ++-- app/utils/system.py | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 282fb797..37ebcdfb 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -13,9 +13,9 @@ from dotenv import set_key from pydantic import BaseModel, BaseSettings, validator, Field from app.log import logger, log_settings, LogConfigModel +from app.schemas import MediaType from app.utils.system import SystemUtils from app.utils.url import UrlUtils -from app.schemas import MediaType from version import APP_VERSION @@ -515,7 +515,7 @@ class Settings(BaseSettings, ConfigModel, LogConfigModel): """ 全局用户代理字符串 """ - return f"{self.PROJECT_NAME}/{APP_VERSION[1:]} ({platform.system()}/{platform.release()})" + return f"{self.PROJECT_NAME}/{APP_VERSION[1:]} ({platform.system()} {platform.release()}; {SystemUtils.cup_arch()})" @property def INNER_CONFIG_PATH(self): diff --git a/app/utils/system.py b/app/utils/system.py index bc47f5b3..38424609 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -96,7 +96,30 @@ class SystemUtils: """ 判断是否为ARM64架构 """ - return True if platform.machine() == 'aarch64' else False + return True if platform.machine().lower() in ('aarch64', 'arm64') else False + + @staticmethod + def is_aarch() -> bool: + """ + 判断是否为ARM32架构 + """ + arch_name = platform.machine().lower() + is_arm_prefix = True if arch_name.startswith('arm') or arch_name.startswith('aarch') else False + return True if (is_arm_prefix and arch_name not in ('aarch64', 'arm64')) else False + + @staticmethod + def is_x86_64() -> bool: + """ + 判断是否为AMD64架构 + """ + return True if platform.machine().lower() in ('amd64', 'x86_64') else False + + @staticmethod + def is_x86_32() -> bool: + """ + 判断是否为AMD32架构 + """ + return True if platform.machine().lower() in ('i386', 'i686', 'x86', '386', 'x86_32') else False @staticmethod def platform() -> str: @@ -112,6 +135,22 @@ class SystemUtils: else: return "Linux" + @staticmethod + def cpu_arch() -> str: + """ + 获取CPU架构 + """ + if SystemUtils.is_x86_64(): + return "x86_64" + elif SystemUtils.is_x86_32(): + return "x86_32" + elif SystemUtils.is_aarch64(): + return "Arm64" + elif SystemUtils.is_aarch(): + return "Arm32" + else: + return platform.machine() + @staticmethod def copy(src: Path, dest: Path) -> Tuple[int, str]: """ From cacfde81667783167edb9a980903a2f55f490e26 Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:14:52 +0800 Subject: [PATCH 2/4] fix --- app/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/config.py b/app/core/config.py index 37ebcdfb..6da02a2b 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -515,7 +515,7 @@ class Settings(BaseSettings, ConfigModel, LogConfigModel): """ 全局用户代理字符串 """ - return f"{self.PROJECT_NAME}/{APP_VERSION[1:]} ({platform.system()} {platform.release()}; {SystemUtils.cup_arch()})" + return f"{self.PROJECT_NAME}/{APP_VERSION[1:]} ({platform.system()} {platform.release()}; {SystemUtils.cpu_arch()})" @property def INNER_CONFIG_PATH(self): From 6519ad25ca0db3662a4c4e84bf79e39e9347178a Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:17:04 +0800 Subject: [PATCH 3/4] fix is_aarch --- app/utils/system.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/utils/system.py b/app/utils/system.py index 38424609..5309e023 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -104,8 +104,7 @@ class SystemUtils: 判断是否为ARM32架构 """ arch_name = platform.machine().lower() - is_arm_prefix = True if arch_name.startswith('arm') or arch_name.startswith('aarch') else False - return True if (is_arm_prefix and arch_name not in ('aarch64', 'arm64')) else False + return True if (arch_name.startswith(('arm', 'aarch')) and arch_name not in ('aarch64', 'arm64')) else False @staticmethod def is_x86_64() -> bool: From 1973a26e83e5fb00698fc5866199e32ad079cac6 Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:19:48 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=AE=80=E5=8C=96=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/system.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/utils/system.py b/app/utils/system.py index 5309e023..1b3848ae 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -68,35 +68,35 @@ class SystemUtils: """ if SystemUtils.is_windows(): return False - return True if "synology" in SystemUtils.execute('uname -a') else False + return "synology" in SystemUtils.execute('uname -a') @staticmethod def is_windows() -> bool: """ 判断是否为Windows系统 """ - return True if os.name == "nt" else False + return os.name == "nt" @staticmethod def is_frozen() -> bool: """ 判断是否为冻结的二进制文件 """ - return True if getattr(sys, 'frozen', False) else False + return getattr(sys, 'frozen', False) @staticmethod def is_macos() -> bool: """ 判断是否为MacOS系统 """ - return True if platform.system() == 'Darwin' else False + return platform.system() == 'Darwin' @staticmethod def is_aarch64() -> bool: """ 判断是否为ARM64架构 """ - return True if platform.machine().lower() in ('aarch64', 'arm64') else False + return platform.machine().lower() in ('aarch64', 'arm64') @staticmethod def is_aarch() -> bool: @@ -104,21 +104,21 @@ class SystemUtils: 判断是否为ARM32架构 """ arch_name = platform.machine().lower() - return True if (arch_name.startswith(('arm', 'aarch')) and arch_name not in ('aarch64', 'arm64')) else False + return arch_name.startswith(('arm', 'aarch')) and arch_name not in ('aarch64', 'arm64') @staticmethod def is_x86_64() -> bool: """ 判断是否为AMD64架构 """ - return True if platform.machine().lower() in ('amd64', 'x86_64') else False + return platform.machine().lower() in ('amd64', 'x86_64') @staticmethod def is_x86_32() -> bool: """ 判断是否为AMD32架构 """ - return True if platform.machine().lower() in ('i386', 'i686', 'x86', '386', 'x86_32') else False + return platform.machine().lower() in ('i386', 'i686', 'x86', '386', 'x86_32') @staticmethod def platform() -> str: