Fix: Fixed an issue where the Sync Now button became unresponsive due to duplicate API calls.
This commit is contained in:
-50
@@ -473,56 +473,6 @@ async def sync_events(request: Request):
|
||||
|
||||
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")
|
||||
async def api_sync(payload: SyncRequest):
|
||||
server_config.load()
|
||||
|
||||
Reference in New Issue
Block a user