mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-23 06:24:48 +00:00
Add partition by file size (#497)
This commit is contained in:
@@ -31,8 +31,9 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
||||
[CommandOption("before", Description = "Only include messages sent before this date or message ID.")]
|
||||
public Snowflake? Before { get; init; }
|
||||
|
||||
[CommandOption("partition", 'p', Description = "Split output into partitions limited to this number of messages.")]
|
||||
public int? PartitionLimit { get; init; }
|
||||
[CommandOption("partition", 'p', Converter = typeof(PartitionConverter),
|
||||
Description = "Split output into partitions limited to this number of messages or a maximum file size (e.g. \"25mb\").")]
|
||||
public IPartitioner Partitoner { get; init; } = new NullPartitioner();
|
||||
|
||||
[CommandOption("parallel", Description = "Limits how many channels can be exported in parallel.")]
|
||||
public int ParallelLimit { get; init; } = 1;
|
||||
@@ -74,7 +75,7 @@ namespace DiscordChatExporter.Cli.Commands.Base
|
||||
ExportFormat,
|
||||
After,
|
||||
Before,
|
||||
PartitionLimit,
|
||||
Partitoner,
|
||||
ShouldDownloadMedia,
|
||||
ShouldReuseMedia,
|
||||
DateFormat
|
||||
|
||||
28
DiscordChatExporter.Cli/Commands/Base/PartitionConverter.cs
Normal file
28
DiscordChatExporter.Cli/Commands/Base/PartitionConverter.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ByteSizeLib;
|
||||
using CliFx.Extensibility;
|
||||
using DiscordChatExporter.Core;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Commands.Base
|
||||
{
|
||||
public class PartitionConverter : BindingConverter<IPartitioner>
|
||||
{
|
||||
public override IPartitioner Convert(string? rawValue)
|
||||
{
|
||||
if (rawValue == null) return new NullPartitioner();
|
||||
|
||||
if (ByteSize.TryParse(rawValue, out ByteSize filesize))
|
||||
{
|
||||
return new FileSizePartitioner((long)filesize.Bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
int messageLimit = int.Parse(rawValue);
|
||||
return new MessageCountPartitioner(messageLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user