Compare commits
2 Commits
15e7636a92
...
3f43662c1f
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f43662c1f | |||
| aa4517aaf5 |
-50
@@ -473,56 +473,6 @@ async def sync_events(request: Request):
|
|||||||
|
|
||||||
return StreamingResponse(event_generator(), media_type="text/event-stream")
|
return StreamingResponse(event_generator(), media_type="text/event-stream")
|
||||||
|
|
||||||
@app.post("/api/sync")
|
|
||||||
async def api_sync(payload: SyncRequest):
|
|
||||||
server_config.load()
|
|
||||||
try:
|
|
||||||
sync_mode = payload.mode or SyncMode(server_config.sync_mode)
|
|
||||||
except ValueError as exc:
|
|
||||||
raise HTTPException(status_code=400, detail=str(exc))
|
|
||||||
|
|
||||||
# Update config temporarily for this sync if needed, but sync_manager reads from config.
|
|
||||||
# If payload overrides config, we might need to handle that.
|
|
||||||
# However, sync_manager._perform_sync reads from server_config.
|
|
||||||
# If we want to support one-off sync with custom params via sync_manager, we need to update sync_manager.
|
|
||||||
|
|
||||||
# For now, let's assume payload params should be saved or used.
|
|
||||||
# But sync_manager is designed to run background tasks too.
|
|
||||||
|
|
||||||
# If we want to keep the existing behavior of api_sync (blocking and returning stats),
|
|
||||||
# we can use sync_manager.run_sync(wait=True).
|
|
||||||
# But we need to make sure sync_manager uses the params from payload if provided.
|
|
||||||
|
|
||||||
# Since sync_manager reads from server_config, let's update server_config if payload has values.
|
|
||||||
# Or better, pass params to sync_manager.run_sync?
|
|
||||||
# sync_manager._perform_sync currently hardcodes reading from server_config.
|
|
||||||
|
|
||||||
# Let's stick to the requirement: "watchdog当发现更改时,执行同步,同步时UI页面也会显示正在同步状态。"
|
|
||||||
# This implies we need a shared state.
|
|
||||||
|
|
||||||
# If I change api_sync to use sync_manager, I need to ensure it supports the custom params.
|
|
||||||
# But payload.local_path and payload.mode are optional.
|
|
||||||
|
|
||||||
# Let's modify sync_manager to accept overrides.
|
|
||||||
# But wait, sync_manager is a singleton.
|
|
||||||
|
|
||||||
# For this task, I will just wrap the existing logic in sync_manager.run_sync(wait=True)
|
|
||||||
# AND I will modify sync_manager to allow passing explicit args to _perform_sync.
|
|
||||||
|
|
||||||
# But first, let's update api_sync to use sync_manager.run_sync(wait=True)
|
|
||||||
# AND we need to handle the parameter passing.
|
|
||||||
|
|
||||||
# Actually, looking at sync_manager implementation I just wrote:
|
|
||||||
# def _perform_sync(self):
|
|
||||||
# server_config.load()
|
|
||||||
# return sync_all_playlists(local_dir=server_config.local_path, mode=SyncMode(server_config.sync_mode))
|
|
||||||
|
|
||||||
# It ignores arguments. This is a limitation.
|
|
||||||
# I should update SyncManager to accept kwargs for sync_all_playlists.
|
|
||||||
|
|
||||||
# Let's update SyncManager first.
|
|
||||||
pass
|
|
||||||
|
|
||||||
@app.post("/api/sync")
|
@app.post("/api/sync")
|
||||||
async def api_sync(payload: SyncRequest):
|
async def api_sync(payload: SyncRequest):
|
||||||
server_config.load()
|
server_config.load()
|
||||||
|
|||||||
+2
-1
@@ -61,7 +61,8 @@ class ServerConfig:
|
|||||||
self.schedule_weekly_days = config.get("schedule_weekly_days", [0])
|
self.schedule_weekly_days = config.get("schedule_weekly_days", [0])
|
||||||
self.schedule_weekly_time = config.get("schedule_weekly_time", "03:00")
|
self.schedule_weekly_time = config.get("schedule_weekly_time", "03:00")
|
||||||
self.schedule_auto_watch = config.get("schedule_auto_watch", False)
|
self.schedule_auto_watch = config.get("schedule_auto_watch", False)
|
||||||
logger.info(f"Server config loaded: {self.__dict__}")
|
logger.info(f"Server config loaded.")
|
||||||
|
logger.debug(f"Current server config: {self.__dict__}")
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
config = {
|
config = {
|
||||||
|
|||||||
+23
-1
@@ -4,7 +4,29 @@ import os
|
|||||||
LOG_PATH = os.path.abspath(
|
LOG_PATH = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), "..", "logs", "app.log"))
|
os.path.join(os.path.dirname(__file__), "..", "logs", "app.log"))
|
||||||
|
|
||||||
LOG_LEVEL = logging.DEBUG
|
def _get_log_level():
|
||||||
|
"""Get log level from environment variable."""
|
||||||
|
level_str = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||||
|
|
||||||
|
# Try to convert to integer
|
||||||
|
if level_str.isdigit():
|
||||||
|
return int(level_str)
|
||||||
|
|
||||||
|
# Map string to logging level
|
||||||
|
levels = {
|
||||||
|
"CRITICAL": logging.CRITICAL,
|
||||||
|
"FATAL": logging.FATAL,
|
||||||
|
"ERROR": logging.ERROR,
|
||||||
|
"WARN": logging.WARNING,
|
||||||
|
"WARNING": logging.WARNING,
|
||||||
|
"INFO": logging.INFO,
|
||||||
|
"DEBUG": logging.DEBUG,
|
||||||
|
"NOTSET": logging.NOTSET,
|
||||||
|
}
|
||||||
|
|
||||||
|
return levels.get(level_str, logging.INFO)
|
||||||
|
|
||||||
|
LOG_LEVEL = _get_log_level()
|
||||||
|
|
||||||
def logger_initialize() -> logging.Logger:
|
def logger_initialize() -> logging.Logger:
|
||||||
"""Initialize the logger for the application. Return a logger that logs to console and a app.log."""
|
"""Initialize the logger for the application. Return a logger that logs to console and a app.log."""
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ def _read_text_if_exists(path: str) -> tuple[str, bool]:
|
|||||||
def _save_playlist_to_folder(filename: str, paths: Sequence[str], folder: str) -> str:
|
def _save_playlist_to_folder(filename: str, paths: Sequence[str], folder: str) -> str:
|
||||||
_ensure_test_dir(folder)
|
_ensure_test_dir(folder)
|
||||||
file_path = os.path.join(folder, filename)
|
file_path = os.path.join(folder, filename)
|
||||||
|
logger.info(f"Saving playlist to: {file_path}")
|
||||||
|
|
||||||
new_content = save_paths(paths)
|
new_content = save_paths(paths)
|
||||||
|
|
||||||
@@ -585,6 +586,7 @@ def sync_all_playlists(
|
|||||||
server_config.load()
|
server_config.load()
|
||||||
compiled_rules = _compile_regex_rules(server_config.path_rules)
|
compiled_rules = _compile_regex_rules(server_config.path_rules)
|
||||||
_ensure_test_dir(test_folder)
|
_ensure_test_dir(test_folder)
|
||||||
|
logger.info(f"Syncing playlists to test folder: {test_folder}")
|
||||||
local_playlists = _load_local_playlists(local_dir)
|
local_playlists = _load_local_playlists(local_dir)
|
||||||
remote_playlists = _fetch_remote_playlists()
|
remote_playlists = _fetch_remote_playlists()
|
||||||
playlist_names: set[str] = set(local_playlists.keys())
|
playlist_names: set[str] = set(local_playlists.keys())
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
- PYTHONDONTWRITEBYTECODE=1
|
- PYTHONDONTWRITEBYTECODE=1
|
||||||
|
- LOG_LEVEL=INFO
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user