From 9467c9a14077772a4cd670f178db7eb413ddcba8 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/user_manager.py b/app/user_manager.py index 55e7e81e3..5193d6a59 100644 --- a/app/user_manager.py +++ b/app/user_manager.py @@ -400,11 +400,24 @@ class UserManager(): try: body = await request.read() + # 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_body = json.dumps(json_data, indent=2).encode('utf-8') + except (json.JSONDecodeError, UnicodeDecodeError): + # If JSON parsing fails, save as-is + formatted_body = body + else: + # Non-JSON files are saved as-is + formatted_body = body + dir_name = os.path.dirname(path) fd, tmp_path = tempfile.mkstemp(dir=dir_name) try: with os.fdopen(fd, "wb") as f: - f.write(body) + f.write(formatted_body) os.replace(tmp_path, path) except: os.unlink(tmp_path)