Integrate React frontend with backend API
This commit is contained in:
@@ -17,6 +17,9 @@ class ServerConfig:
|
||||
self.port = "32400"
|
||||
self.library_name = ""
|
||||
self.path_rules: list[dict[str, str]] = []
|
||||
# 新增:本地播放列表目录和默认同步策略(用于新的前端界面)
|
||||
self.local_playlist_dir = os.getenv("LOCAL_PLAYLIST_DIR", "playlist")
|
||||
self.sync_strategy = "LOCAL_OVERWRITE"
|
||||
self.load()
|
||||
|
||||
def load(self) -> None:
|
||||
@@ -41,6 +44,10 @@ class ServerConfig:
|
||||
self.port = config.get("server_port", "32400")
|
||||
self.library_name = config.get("library_name", "")
|
||||
self.path_rules = config.get("path_rules", []) or []
|
||||
self.local_playlist_dir = config.get(
|
||||
"local_playlist_dir", self.local_playlist_dir
|
||||
)
|
||||
self.sync_strategy = config.get("sync_strategy", self.sync_strategy)
|
||||
logger.info(f"Server config loaded: {self.__dict__}")
|
||||
|
||||
def save(self):
|
||||
@@ -52,6 +59,8 @@ class ServerConfig:
|
||||
"server_port": self.port,
|
||||
"library_name": self.library_name,
|
||||
"path_rules": self.path_rules,
|
||||
"local_playlist_dir": self.local_playlist_dir,
|
||||
"sync_strategy": self.sync_strategy,
|
||||
}
|
||||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=4, ensure_ascii=False)
|
||||
@@ -82,6 +91,13 @@ class ServerConfig:
|
||||
def set_path_rules(self, path_rules: list[dict[str, str]]) -> None:
|
||||
self.path_rules = path_rules or []
|
||||
|
||||
def set_local_playlist_dir(self, playlist_dir: str) -> None:
|
||||
if playlist_dir:
|
||||
self.local_playlist_dir = playlist_dir
|
||||
|
||||
def set_sync_strategy(self, sync_strategy: str) -> None:
|
||||
self.sync_strategy = sync_strategy
|
||||
|
||||
def set_and_save_config(
|
||||
self,
|
||||
theme: str = None,
|
||||
@@ -91,6 +107,8 @@ class ServerConfig:
|
||||
port: str = None,
|
||||
library_name: str | None = None,
|
||||
path_rules: list[dict[str, str]] | None = None,
|
||||
local_playlist_dir: str | None = None,
|
||||
sync_strategy: str | None = None,
|
||||
) -> None:
|
||||
if theme is not None:
|
||||
self.set_theme(theme)
|
||||
@@ -106,6 +124,10 @@ class ServerConfig:
|
||||
self.set_library(library_name)
|
||||
if path_rules is not None:
|
||||
self.set_path_rules(path_rules)
|
||||
if local_playlist_dir is not None:
|
||||
self.set_local_playlist_dir(local_playlist_dir)
|
||||
if sync_strategy is not None:
|
||||
self.set_sync_strategy(sync_strategy)
|
||||
self.save()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user