Rename command, adjust docs

This commit is contained in:
Ben Rucker 2026-01-16 19:38:55 -08:00
parent e85ca90dd4
commit 076d038c1a
8 changed files with 21 additions and 22 deletions

View file

@ -97,16 +97,16 @@ public abstract class ExportCommandBase : DiscordCommandBase
[CommandOption( [CommandOption(
"reuse-media", "reuse-media",
Description = "Reuse previously downloaded assets to avoid redundant requests." Description = "Reuse previously downloaded assets to avoid redundant requests. "
+ "Keep --media-nested consistent across runs for best results."
)] )]
public bool ShouldReuseAssets { get; init; } = false; public bool ShouldReuseAssets { get; init; } = false;
[CommandOption( [CommandOption(
"new-media-paths", "media-nested",
Description = "Saves media with a new file naming convention to prevent collisions. " Description = "Saves assets with a nested file naming convention, creating subdirectories for each distinct asset type."
+ "Duplicate media may be downloaded if consecutive runs use different values for this flag."
)] )]
public bool ShouldUseNewMediaFilePaths { get; init; } = false; public bool ShouldUseNestedMediaFilePaths { get; init; } = false;
[CommandOption( [CommandOption(
"media-dir", "media-dir",
@ -162,9 +162,9 @@ public abstract class ExportCommandBase : DiscordCommandBase
} }
// New media file path can only be enabled if the download assets option is set // New media file path can only be enabled if the download assets option is set
if (ShouldUseNewMediaFilePaths && !ShouldDownloadAssets) if (ShouldUseNestedMediaFilePaths && !ShouldDownloadAssets)
{ {
throw new CommandException("Option --new-media-paths cannot be used without --media."); throw new CommandException("Option --media-nested cannot be used without --media.");
} }
// Assets directory can only be specified if the download assets option is set // Assets directory can only be specified if the download assets option is set
@ -283,7 +283,7 @@ public abstract class ExportCommandBase : DiscordCommandBase
ShouldFormatMarkdown, ShouldFormatMarkdown,
ShouldDownloadAssets, ShouldDownloadAssets,
ShouldReuseAssets, ShouldReuseAssets,
ShouldUseNewMediaFilePaths, ShouldUseNestedMediaFilePaths,
Locale, Locale,
IsUtcNormalizationEnabled IsUtcNormalizationEnabled
); );

View file

@ -16,7 +16,7 @@ namespace DiscordChatExporter.Core.Exporting;
internal partial class ExportAssetDownloader( internal partial class ExportAssetDownloader(
string workingDirPath, string workingDirPath,
bool reuse, bool reuse,
bool useNewMediaFilePaths bool useNestedMediaFilePaths
) )
{ {
private static readonly AsyncKeyedLocker<string> Locker = new(); private static readonly AsyncKeyedLocker<string> Locker = new();
@ -29,7 +29,7 @@ internal partial class ExportAssetDownloader(
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var localFilePath = useNewMediaFilePaths var localFilePath = useNestedMediaFilePaths
? GetFilePathFromUrl(url) ? GetFilePathFromUrl(url)
: GetFileNameFromUrlLegacy(url); : GetFileNameFromUrlLegacy(url);
var filePath = Path.Combine(workingDirPath, localFilePath); var filePath = Path.Combine(workingDirPath, localFilePath);
@ -77,7 +77,6 @@ internal partial class ExportAssetDownloader
// If this isn't a Discord CDN URL, save the file to the `media/external` folder. // If this isn't a Discord CDN URL, save the file to the `media/external` folder.
if (!string.Equals(uri.Host, "cdn.discordapp.com", StringComparison.OrdinalIgnoreCase)) if (!string.Equals(uri.Host, "cdn.discordapp.com", StringComparison.OrdinalIgnoreCase))
{ {
File.AppendAllTextAsync("external_urls.txt", $"{url}\n");
return $"external/{uri.Host}{uri.AbsolutePath}"; return $"external/{uri.Host}{uri.AbsolutePath}";
} }

View file

@ -22,7 +22,7 @@ internal class ExportContext(DiscordClient discord, ExportRequest request)
private readonly ExportAssetDownloader _assetDownloader = new( private readonly ExportAssetDownloader _assetDownloader = new(
request.AssetsDirPath, request.AssetsDirPath,
request.ShouldReuseAssets, request.ShouldReuseAssets,
request.ShouldUseNewMediaFilePaths request.ShouldUseNestedMediaFilePaths
); );
public DiscordClient Discord { get; } = discord; public DiscordClient Discord { get; } = discord;

View file

@ -39,7 +39,7 @@ public partial class ExportRequest
public bool ShouldReuseAssets { get; } public bool ShouldReuseAssets { get; }
public bool ShouldUseNewMediaFilePaths { get; } public bool ShouldUseNestedMediaFilePaths { get; }
public string? Locale { get; } public string? Locale { get; }
@ -60,7 +60,7 @@ public partial class ExportRequest
bool shouldFormatMarkdown, bool shouldFormatMarkdown,
bool shouldDownloadAssets, bool shouldDownloadAssets,
bool shouldReuseAssets, bool shouldReuseAssets,
bool shouldUseNewMediaFilePaths, bool shouldUseNestedMediaFilePaths,
string? locale, string? locale,
bool isUtcNormalizationEnabled bool isUtcNormalizationEnabled
) )
@ -75,7 +75,7 @@ public partial class ExportRequest
ShouldFormatMarkdown = shouldFormatMarkdown; ShouldFormatMarkdown = shouldFormatMarkdown;
ShouldDownloadAssets = shouldDownloadAssets; ShouldDownloadAssets = shouldDownloadAssets;
ShouldReuseAssets = shouldReuseAssets; ShouldReuseAssets = shouldReuseAssets;
ShouldUseNewMediaFilePaths = shouldUseNewMediaFilePaths; ShouldUseNestedMediaFilePaths = shouldUseNestedMediaFilePaths;
Locale = locale; Locale = locale;
IsUtcNormalizationEnabled = isUtcNormalizationEnabled; IsUtcNormalizationEnabled = isUtcNormalizationEnabled;

View file

@ -67,7 +67,7 @@ public partial class SettingsService()
public partial bool LastShouldReuseAssets { get; set; } public partial bool LastShouldReuseAssets { get; set; }
[ObservableProperty] [ObservableProperty]
public partial bool LastShouldUseNewMediaFilePaths { get; set; } public partial bool LastShouldUseNestedMediaFilePaths { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string? LastAssetsDirPath { get; set; } public partial string? LastAssetsDirPath { get; set; }

View file

@ -276,7 +276,7 @@ public partial class DashboardViewModel : ViewModelBase
dialog.ShouldFormatMarkdown, dialog.ShouldFormatMarkdown,
dialog.ShouldDownloadAssets, dialog.ShouldDownloadAssets,
dialog.ShouldReuseAssets, dialog.ShouldReuseAssets,
dialog.ShouldUseNewMediaFilePaths, dialog.ShouldUseNestedMediaFilePaths,
_settingsService.Locale, _settingsService.Locale,
_settingsService.IsUtcNormalizationEnabled _settingsService.IsUtcNormalizationEnabled
); );

View file

@ -68,7 +68,7 @@ public partial class ExportSetupViewModel(
public partial bool ShouldReuseAssets { get; set; } public partial bool ShouldReuseAssets { get; set; }
[ObservableProperty] [ObservableProperty]
public partial bool ShouldUseNewMediaFilePaths { get; set; } public partial bool ShouldUseNestedMediaFilePaths { get; set; }
[ObservableProperty] [ObservableProperty]
public partial string? AssetsDirPath { get; set; } public partial string? AssetsDirPath { get; set; }
@ -108,7 +108,7 @@ public partial class ExportSetupViewModel(
ShouldFormatMarkdown = settingsService.LastShouldFormatMarkdown; ShouldFormatMarkdown = settingsService.LastShouldFormatMarkdown;
ShouldDownloadAssets = settingsService.LastShouldDownloadAssets; ShouldDownloadAssets = settingsService.LastShouldDownloadAssets;
ShouldReuseAssets = settingsService.LastShouldReuseAssets; ShouldReuseAssets = settingsService.LastShouldReuseAssets;
ShouldUseNewMediaFilePaths = settingsService.LastShouldUseNewMediaFilePaths; ShouldUseNestedMediaFilePaths = settingsService.LastShouldUseNestedMediaFilePaths;
AssetsDirPath = settingsService.LastAssetsDirPath; AssetsDirPath = settingsService.LastAssetsDirPath;
// Show the "advanced options" section by default if any // Show the "advanced options" section by default if any
@ -187,7 +187,7 @@ public partial class ExportSetupViewModel(
settingsService.LastShouldFormatMarkdown = ShouldFormatMarkdown; settingsService.LastShouldFormatMarkdown = ShouldFormatMarkdown;
settingsService.LastShouldDownloadAssets = ShouldDownloadAssets; settingsService.LastShouldDownloadAssets = ShouldDownloadAssets;
settingsService.LastShouldReuseAssets = ShouldReuseAssets; settingsService.LastShouldReuseAssets = ShouldReuseAssets;
settingsService.LastShouldUseNewMediaFilePaths = ShouldUseNewMediaFilePaths; settingsService.LastShouldUseNestedMediaFilePaths = ShouldUseNestedMediaFilePaths;
settingsService.LastAssetsDirPath = AssetsDirPath; settingsService.LastAssetsDirPath = AssetsDirPath;
Close(true); Close(true);

View file

@ -280,8 +280,8 @@
IsEnabled="{Binding ShouldDownloadAssets}" IsEnabled="{Binding ShouldDownloadAssets}"
LastChildFill="False" LastChildFill="False"
ToolTip.Tip="Uses a new organization to save media files to avoid data loss. If you change this setting from run to run, duplicate media may be downloaded."> ToolTip.Tip="Uses a new organization to save media files to avoid data loss. If you change this setting from run to run, duplicate media may be downloaded.">
<TextBlock DockPanel.Dock="Left" Text="Use new media file paths" /> <TextBlock DockPanel.Dock="Left" Text="Use nested media file paths" />
<ToggleSwitch DockPanel.Dock="Right" IsChecked="{Binding ShouldUseNewMediaFilePaths}" /> <ToggleSwitch DockPanel.Dock="Right" IsChecked="{Binding ShouldUseNestedMediaFilePaths}" />
</DockPanel> </DockPanel>
<!-- Assets path --> <!-- Assets path -->