logger added.

plex_client method naming fix.
This commit is contained in:
2025-07-19 18:00:48 +09:00
parent 65bd99d3f2
commit c3d1662465
4 changed files with 52 additions and 4 deletions
+8 -2
View File
@@ -1,5 +1,6 @@
import json
import os
from app.utils.logger import logger
CONFIG_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "config.json")
@@ -20,20 +21,23 @@ class ServerConfig:
try:
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
config = json.load(f)
logger.debug(f"Loaded server config: {config}")
except FileNotFoundError:
# 如果配置文件不存在,使用默认值
self.save()
logger.debug("Config file not found, using default values.")
return
except json.JSONDecodeError:
# 如果配置文件格式错误,使用默认值
self.save()
logger.debug("Config file is invalid, using default values.")
return
self.theme = config.get("theme", "auto")
self.token = config.get("token", "")
self.url = config.get("server_url", "")
self.scheme = config.get("server_scheme", "https")
self.port = config.get("server_port", "32400")
logger.info(f"Server config loaded: {self.__dict__}")
def save(self):
config = {
@@ -45,6 +49,7 @@ class ServerConfig:
}
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(config, f, indent=4, ensure_ascii=False)
logger.info(f"Server config saved: {config}")
def set_url(self, url: str) -> None:
self.url = url
@@ -61,10 +66,11 @@ class ServerConfig:
def set_theme(self, theme: str) -> None:
# check theme is valid
if theme not in ["auto", "dark", "light"]:
logger.error(f"Invalid theme: {theme}")
raise ValueError("Invalid theme. Must be 'auto', 'dark', or 'light'.")
self.theme = theme
def set_config(
def set_and_save_config(
self,
theme: str = None,
token: str = None,