fix config: handle stringified JSON in API requests
ConfigUpdate fields (scheduler, logging, backup, nfo, other) arrive as strings from frontend. Parse JSON or ast.literal_eval before validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -47,8 +47,19 @@ async def update_config(
|
||||
from src.config.settings import settings as app_settings
|
||||
|
||||
anime_dir_changed = False
|
||||
if update.other and update.other.get("anime_directory"):
|
||||
anime_dir = update.other.get("anime_directory")
|
||||
other_data = update.other
|
||||
if isinstance(other_data, str):
|
||||
try:
|
||||
import ast
|
||||
other_data = ast.literal_eval(other_data)
|
||||
except (ValueError, SyntaxError):
|
||||
try:
|
||||
import json
|
||||
other_data = json.loads(other_data)
|
||||
except (ValueError, json.JSONDecodeError):
|
||||
other_data = None
|
||||
if other_data and other_data.get("anime_directory"):
|
||||
anime_dir = other_data.get("anime_directory")
|
||||
if anime_dir and not app_settings.anime_directory:
|
||||
app_settings.anime_directory = str(anime_dir)
|
||||
anime_dir_changed = True
|
||||
|
||||
Reference in New Issue
Block a user