From 0eff10fd2190da071f0450cd97becab68a9911c7 Mon Sep 17 00:00:00 2001 From: Sam Pullara Date: Wed, 29 Oct 2025 13:17:56 -0700 Subject: [PATCH] store json files pretty printed for better source control compatibiility --- app/user_manager.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/user_manager.py b/app/user_manager.py index a2d376c0c..f62901cf7 100644 --- a/app/user_manager.py +++ b/app/user_manager.py @@ -366,8 +366,22 @@ class UserManager(): try: body = await request.read() - with open(path, "wb") as f: - f.write(body) + # Pretty print JSON files for better source control + if path.lower().endswith('.json'): + try: + # Parse JSON and re-serialize with indentation + json_data = json.loads(body.decode('utf-8')) + formatted_json = json.dumps(json_data, indent=2) + with open(path, "w", encoding='utf-8') as f: + f.write(formatted_json) + except (json.JSONDecodeError, UnicodeDecodeError): + # If JSON parsing fails, save as-is + with open(path, "wb") as f: + f.write(body) + else: + # Non-JSON files are saved as-is + with open(path, "wb") as f: + f.write(body) except OSError as e: logging.warning(f"Error saving file '{path}': {e}") return web.Response(