From 3e7fd45589f882875607afc861c1018cc7ae4bf8 Mon Sep 17 00:00:00 2001 From: Grey Lee Date: Sat, 13 Sep 2025 17:41:22 +0800 Subject: [PATCH] Add DisableTextSanitization config option and update related logic --- OF DL/Entities/Config.cs | 4 ++++ OF DL/Program.cs | 21 +++++++++++++++------ OF DL/Utils/XmlUtils.cs | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/OF DL/Entities/Config.cs b/OF DL/Entities/Config.cs index 0d05fbf..0934422 100644 --- a/OF DL/Entities/Config.cs +++ b/OF DL/Entities/Config.cs @@ -103,6 +103,10 @@ namespace OF_DL.Entities [JsonConverter(typeof(StringEnumConverter))] public VideoResolution DownloadVideoResolution { get; set; } = VideoResolution.source; + + // When enabled, post/message text is stored as-is without XML stripping. + [ToggleableConfig] + public bool DisableTextSanitization { get; set; } = false; } public class CreatorConfig : IFileNameFormatConfig diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 86c9d87..19a2be0 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -160,6 +160,7 @@ public class Program hoconConfig.AppendLine($" DownloadDateSelection = \"{jsonConfig.DownloadDateSelection.ToString().ToLower()}\""); hoconConfig.AppendLine($" CustomDate = \"{jsonConfig.CustomDate?.ToString("yyyy-MM-dd")}\""); hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}"); + hoconConfig.AppendLine($" DisableTextSanitization = false"); hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\""); hoconConfig.AppendLine("}"); @@ -247,7 +248,7 @@ public class Program { string hoconText = File.ReadAllText("config.conf"); - var hoconConfig = ConfigurationFactory.ParseString(hoconText); + var hoconConfig = ConfigurationFactory.ParseString(hoconText); config = new Entities.Config { @@ -279,7 +280,9 @@ public class Program DownloadOnlySpecificDates = hoconConfig.GetBoolean("Download.DownloadOnlySpecificDates"), DownloadDateSelection = Enum.Parse(hoconConfig.GetString("Download.DownloadDateSelection"), true), CustomDate = !string.IsNullOrWhiteSpace(hoconConfig.GetString("Download.CustomDate")) ? DateTime.Parse(hoconConfig.GetString("Download.CustomDate")) : null, - ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"), + ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"), + // Optional flag; default to false when missing + DisableTextSanitization = bool.TryParse(hoconConfig.GetString("Download.DisableTextSanitization", "false"), out var dts) ? dts : false, DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution", "source")), // File Settings @@ -344,7 +347,9 @@ public class Program } } - levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config + levelSwitch.MinimumLevel = (LogEventLevel)config.LoggingLevel; //set the logging level based on config + // Apply text sanitization preference globally + OF_DL.Utils.XmlUtils.Passthrough = config.DisableTextSanitization; Log.Debug("Configuration:"); string configString = JsonConvert.SerializeObject(config, Formatting.Indented); Log.Debug(configString); @@ -399,9 +404,11 @@ public class Program hoconConfig.AppendLine($" DownloadOnlySpecificDates = {jsonConfig.DownloadOnlySpecificDates.ToString().ToLower()}"); hoconConfig.AppendLine($" DownloadDateSelection = \"{jsonConfig.DownloadDateSelection.ToString().ToLower()}\""); hoconConfig.AppendLine($" CustomDate = \"{jsonConfig.CustomDate?.ToString("yyyy-MM-dd")}\""); - hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}"); - hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\""); - hoconConfig.AppendLine("}"); + hoconConfig.AppendLine($" ShowScrapeSize = {jsonConfig.ShowScrapeSize.ToString().ToLower()}"); + // New option defaults to false when converting legacy json + hoconConfig.AppendLine($" DisableTextSanitization = false"); + hoconConfig.AppendLine($" DownloadVideoResolution = \"{(jsonConfig.DownloadVideoResolution == VideoResolution.source ? "source" : jsonConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\""); + hoconConfig.AppendLine("}"); hoconConfig.AppendLine("# File Settings"); hoconConfig.AppendLine("File {"); @@ -2904,6 +2911,7 @@ public class Program hoconConfig.AppendLine($" DownloadDateSelection = \"{newConfig.DownloadDateSelection.ToString().ToLower()}\""); hoconConfig.AppendLine($" CustomDate = \"{newConfig.CustomDate?.ToString("yyyy-MM-dd")}\""); hoconConfig.AppendLine($" ShowScrapeSize = {newConfig.ShowScrapeSize.ToString().ToLower()}"); + hoconConfig.AppendLine($" DisableTextSanitization = {newConfig.DisableTextSanitization.ToString().ToLower()}"); hoconConfig.AppendLine($" DownloadVideoResolution = \"{(newConfig.DownloadVideoResolution == VideoResolution.source ? "source" : newConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\""); hoconConfig.AppendLine("}"); @@ -3063,6 +3071,7 @@ public class Program hoconConfig.AppendLine($" DownloadDateSelection = \"{newConfig.DownloadDateSelection.ToString().ToLower()}\""); hoconConfig.AppendLine($" CustomDate = \"{newConfig.CustomDate?.ToString("yyyy-MM-dd")}\""); hoconConfig.AppendLine($" ShowScrapeSize = {newConfig.ShowScrapeSize.ToString().ToLower()}"); + hoconConfig.AppendLine($" DisableTextSanitization = {newConfig.DisableTextSanitization.ToString().ToLower()}"); hoconConfig.AppendLine($" DownloadVideoResolution = \"{(newConfig.DownloadVideoResolution == VideoResolution.source ? "source" : newConfig.DownloadVideoResolution.ToString().TrimStart('_'))}\""); hoconConfig.AppendLine("}"); diff --git a/OF DL/Utils/XmlUtils.cs b/OF DL/Utils/XmlUtils.cs index d55be10..55a68c6 100644 --- a/OF DL/Utils/XmlUtils.cs +++ b/OF DL/Utils/XmlUtils.cs @@ -9,8 +9,16 @@ namespace OF_DL.Utils { internal static class XmlUtils { + // When true, return original text without parsing/stripping. + public static bool Passthrough { get; set; } = false; + public static string EvaluateInnerText(string xmlValue) { + if (Passthrough) + { + return xmlValue ?? string.Empty; + } + try { var parsedText = XElement.Parse($"{xmlValue}");