mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
feat: 完善数据库备份管理与版本读取 (#6450)
This commit is contained in:
@@ -33,7 +33,7 @@ from app.foundation.environment import (
|
||||
is_frozen,
|
||||
)
|
||||
from app.foundation.url import UrlUtils
|
||||
from version import APP_VERSION
|
||||
from app.runtime.version import get_app_version
|
||||
|
||||
|
||||
class SystemConfModel(BaseModel):
|
||||
@@ -1061,7 +1061,7 @@ class Settings(BaseSettings, ConfigModel, LogConfigModel):
|
||||
全局用户代理字符串
|
||||
"""
|
||||
return (
|
||||
f"{self.PROJECT_NAME}/{APP_VERSION[1:]} "
|
||||
f"{self.PROJECT_NAME}/{get_app_version()[1:]} "
|
||||
f"({platform.system()} {platform.release()}; {cpu_arch()})"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""当前 MoviePilot 部署的产品版本读取入口。"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from app.foundation.environment import is_frozen, is_windows
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.settings import get_runtime_setting
|
||||
from version import APP_VERSION as _APP_VERSION
|
||||
from version import FRONTEND_VERSION as _FRONTEND_VERSION
|
||||
|
||||
|
||||
def get_app_version() -> str:
|
||||
"""返回当前后端构建的发布版本。"""
|
||||
return str(_APP_VERSION)
|
||||
|
||||
|
||||
def _read_version_file(path: Path) -> str | None:
|
||||
"""读取版本文件,文件缺失、内容为空或读取失败时返回空值。"""
|
||||
try:
|
||||
version = path.read_text(encoding="utf-8", errors="replace").strip()
|
||||
return version or None
|
||||
except OSError as error:
|
||||
if path.exists():
|
||||
logger.debug(f"加载版本文件 {path} 出错:{error}")
|
||||
return None
|
||||
|
||||
|
||||
def get_frontend_version(*, fallback_to_declared: bool = True) -> str | None:
|
||||
"""返回当前部署的前端资源版本,并可关闭发布声明回退。"""
|
||||
if is_frozen() and is_windows():
|
||||
version_file = (
|
||||
Path(get_runtime_setting("CONFIG_PATH")).parent
|
||||
/ "nginx"
|
||||
/ "html"
|
||||
/ "version.txt"
|
||||
)
|
||||
else:
|
||||
version_file = Path(get_runtime_setting("FRONTEND_PATH")) / "version.txt"
|
||||
installed_version = _read_version_file(version_file)
|
||||
if installed_version or not fallback_to_declared:
|
||||
return installed_version
|
||||
return str(_FRONTEND_VERSION)
|
||||
Reference in New Issue
Block a user