mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-08-18 13:31:42 +02:00
.github
.idea
app
.idea
Desktop
Resources
Server
Data
Aggregations
Filters
Attachment.cs
Channel.cs
Download.cs
DownloadStatus.cs
DownloadedAttachment.cs
Embed.cs
EmojiFlags.cs
Message.cs
Reaction.cs
Server.cs
ServerType.cs
User.cs
Database
Download
Endpoints
Service
Server.csproj
Utils
.gitignore
Directory.Build.props
DiscordHistoryTracker.sln
Version.cs
build.bat
build.sh
empty.dht
global.json
tools
web
.gitattributes
.gitignore
LICENSE.md
README.md
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using System.Net;
|
|
using DHT.Server.Download;
|
|
|
|
namespace DHT.Server.Data;
|
|
|
|
public readonly struct Download {
|
|
internal static Download NewSuccess(DownloadItem item, byte[] data) {
|
|
return new Download(item.NormalizedUrl, item.DownloadUrl, DownloadStatus.Success, (ulong) Math.Max(data.LongLength, 0), data);
|
|
}
|
|
|
|
internal static Download NewFailure(DownloadItem item, HttpStatusCode? statusCode, ulong size) {
|
|
return new Download(item.NormalizedUrl, item.DownloadUrl, statusCode.HasValue ? (DownloadStatus) (int) statusCode : DownloadStatus.GenericError, size);
|
|
}
|
|
|
|
public string NormalizedUrl { get; }
|
|
public string DownloadUrl { get; }
|
|
public DownloadStatus Status { get; }
|
|
public ulong Size { get; }
|
|
public byte[]? Data { get; }
|
|
|
|
internal Download(string normalizedUrl, string downloadUrl, DownloadStatus status, ulong size, byte[]? data = null) {
|
|
NormalizedUrl = normalizedUrl;
|
|
DownloadUrl = downloadUrl;
|
|
Status = status;
|
|
Size = size;
|
|
Data = data;
|
|
}
|
|
|
|
internal Download WithData(byte[] data) {
|
|
return new Download(NormalizedUrl, DownloadUrl, Status, Size, data);
|
|
}
|
|
}
|