Support GIF embeds when exporting to HTML (#919)
parent
a405ab184e
commit
f28d662a71
@ -0,0 +1,22 @@
|
||||
using JsonExtensions.Reading;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-video-structure
|
||||
public record EmbedVideo(
|
||||
string? Url,
|
||||
string? ProxyUrl,
|
||||
int? Width,
|
||||
int? Height)
|
||||
{
|
||||
public static EmbedVideo Parse(JsonElement json)
|
||||
{
|
||||
var url = json.GetPropertyOrNull("url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var proxyUrl = json.GetPropertyOrNull("proxy_url")?.GetNonWhiteSpaceStringOrNull();
|
||||
var width = json.GetPropertyOrNull("width")?.GetInt32OrNull();
|
||||
var height = json.GetPropertyOrNull("height")?.GetInt32OrNull();
|
||||
|
||||
return new EmbedVideo(url, proxyUrl, width, height);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DiscordChatExporter.Core.Discord.Data.Embeds;
|
||||
|
||||
public partial record GifvEmbedProjection(string Url)
|
||||
{
|
||||
public static GifvEmbedProjection? TryResolve(Embed embed)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(embed.Url))
|
||||
return null;
|
||||
|
||||
if (embed.Video is null || string.IsNullOrWhiteSpace(embed.Video.Url))
|
||||
return null;
|
||||
|
||||
if (!string.Equals(embed.Type, "gifv", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
return new GifvEmbedProjection(embed.Url);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue