mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-23 12:50:18 +08:00
store json files pretty printed for better source control compatibiility
This commit is contained in:
parent
ec4fc2a09a
commit
0eff10fd21
@ -366,8 +366,22 @@ class UserManager():
|
|||||||
try:
|
try:
|
||||||
body = await request.read()
|
body = await request.read()
|
||||||
|
|
||||||
with open(path, "wb") as f:
|
# Pretty print JSON files for better source control
|
||||||
f.write(body)
|
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:
|
except OSError as e:
|
||||||
logging.warning(f"Error saving file '{path}': {e}")
|
logging.warning(f"Error saving file '{path}': {e}")
|
||||||
return web.Response(
|
return web.Response(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user