mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 07:43:31 -07:00
Add test, change params format to use hyphen instead of equals
This commit is contained in:
parent
806d2c38c3
commit
2a4d625157
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]}")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue