From 2a4d62515724fad317d865b923882eb3614bb3ce Mon Sep 17 00:00:00 2001 From: Ben Rucker Date: Fri, 16 Jan 2026 22:05:03 -0800 Subject: [PATCH] Add test, change params format to use hyphen instead of equals --- .../Specs/SelfContainedSpecs.cs | 50 ++++++++++++++++++- .../Exporting/ExportAssetDownloader.cs | 2 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs index b8a2d677..0b5f66e4 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using CliFx.Infrastructure; @@ -39,4 +40,51 @@ public class SelfContainedSpecs .Should() .BeTrue(); } + + [Fact] + public async Task I_can_export_a_channel_and_download_all_referenced_assets_with_nested_paths() + { + // Arrange + using var dir = TempDir.Create(); + var filePath = Path.Combine(dir.Path, "output.html"); + + // Act + await new ExportChannelsCommand + { + Token = Secrets.DiscordToken, + ChannelIds = [ChannelIds.SelfContainedTestCases], + ExportFormat = ExportFormat.HtmlDark, + OutputPath = filePath, + ShouldDownloadAssets = true, + ShouldUseNestedMediaFilePaths = true, + }.ExecuteAsync(new FakeConsole()); + + // DEBUG: Print what's in the HTML vs what exists + var srcPaths = Html.Parse(await File.ReadAllTextAsync(filePath)) + .QuerySelectorAll("body [src]") + .Select(e => e.GetAttribute("src")!) + .ToList(); + + Console.WriteLine("=== SRC paths in HTML ==="); + foreach (var src in srcPaths) + { + var fullPath = Path.GetFullPath(src, dir.Path); + var exists = File.Exists(fullPath); + Console.WriteLine($"{(exists ? "✓" : "✗")} {src}"); + Console.WriteLine($" Full: {fullPath}"); + } + + Console.WriteLine("\n=== Files actually on disk ==="); + foreach (var file in Directory.EnumerateFiles(dir.Path, "*", SearchOption.AllDirectories)) + Console.WriteLine(file); + + // Assert + Html.Parse(await File.ReadAllTextAsync(filePath)) + .QuerySelectorAll("body [src]") + .Select(e => e.GetAttribute("src")!) + .Select(f => Path.GetFullPath(f, dir.Path)) + .All(File.Exists) + .Should() + .BeTrue(); + } } diff --git a/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs b/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs index 2afe02e5..41fdd058 100644 --- a/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs +++ b/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs @@ -128,7 +128,7 @@ internal partial class ExportAssetDownloader "_", query .AllKeys.Where(key => !string.IsNullOrEmpty(key)) - .Select(key => string.IsNullOrEmpty(query[key]) ? key : $"{key}={query[key]}") + .Select(key => string.IsNullOrEmpty(query[key]) ? key : $"{key}-{query[key]}") ); }