From 9b82be9a6ecfb45bdfaf5f0fa5abbe419b0f445f Mon Sep 17 00:00:00 2001 From: Jonas Linter <{email_address}> Date: Mon, 17 Nov 2025 09:13:33 +0100 Subject: [PATCH] Fixed export --- src/alpine_bits_python/api.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/alpine_bits_python/api.py b/src/alpine_bits_python/api.py index 3747c9a..91415cc 100644 --- a/src/alpine_bits_python/api.py +++ b/src/alpine_bits_python/api.py @@ -7,6 +7,7 @@ import multiprocessing import os import traceback import urllib.parse +import xml.dom.minidom from collections import defaultdict from datetime import date, datetime from functools import partial @@ -1323,8 +1324,17 @@ async def handle_xml_upload( extension = Path(filename).suffix or ".xml" log_filename = logs_dir / f"{base_filename}_{username}_{timestamp}{extension}" - # Save XML content to file - log_filename.write_text(xml_content, encoding="utf-8") + # Format and save XML content to file + try: + dom = xml.dom.minidom.parseString(xml_content) + pretty_xml = dom.toprettyxml(indent=" ") + # Remove extra blank lines that toprettyxml adds + pretty_xml = "\n".join([line for line in pretty_xml.split("\n") if line.strip()]) + log_filename.write_text(pretty_xml, encoding="utf-8") + except Exception as e: + # If formatting fails, save the original content + _LOGGER.warning("Failed to format XML: %s. Saving unformatted.", str(e)) + log_filename.write_text(xml_content, encoding="utf-8") _LOGGER.info( "XML file saved to %s by user %s (original: %s)",