Adding a base class of oembedresponse, so we can handle string values for dimentions (#16514)

This commit is contained in:
Elitsa Marinovska
2024-05-31 11:39:09 +02:00
committed by GitHub
parent 71e1b74337
commit 464eaa0409
3 changed files with 79 additions and 60 deletions

View File

@@ -1,68 +1,10 @@
using System.Net;
using System.Runtime.Serialization;
namespace Umbraco.Cms.Core.Media.EmbedProviders;
/// <summary>
/// Wrapper class for OEmbed response
/// Wrapper class for OEmbed response.
/// </summary>
[DataContract]
public class OEmbedResponse
{
[DataMember(Name = "type")]
public string? Type { get; set; }
public class OEmbedResponse : OEmbedResponseBase<double>;
[DataMember(Name = "version")]
public string? Version { get; set; }
[DataMember(Name = "title")]
public string? Title { get; set; }
[DataMember(Name = "author_name")]
public string? AuthorName { get; set; }
[DataMember(Name = "author_url")]
public string? AuthorUrl { get; set; }
[DataMember(Name = "provider_name")]
public string? ProviderName { get; set; }
[DataMember(Name = "provider_url")]
public string? ProviderUrl { get; set; }
[DataMember(Name = "thumbnail_url")]
public string? ThumbnailUrl { get; set; }
[DataMember(Name = "thumbnail_height")]
public double? ThumbnailHeight { get; set; }
[DataMember(Name = "thumbnail_width")]
public double? ThumbnailWidth { get; set; }
[DataMember(Name = "html")]
public string? Html { get; set; }
[DataMember(Name = "url")]
public string? Url { get; set; }
[DataMember(Name = "height")]
public double? Height { get; set; }
[DataMember(Name = "width")]
public double? Width { get; set; }
/// <summary>
/// Gets the HTML.
/// </summary>
/// <returns>The response HTML</returns>
public string GetHtml()
{
if (Type == "photo")
{
return "<img src=\"" + Url + "\" width=\"" + Width + "\" height=\"" + Height + "\" alt=\"" +
WebUtility.HtmlEncode(Title) + "\" />";
}
return string.IsNullOrEmpty(Html) == false ? Html : string.Empty;
}
}

View File

@@ -0,0 +1,68 @@
using System.Net;
using System.Runtime.Serialization;
namespace Umbraco.Cms.Core.Media.EmbedProviders;
/// <summary>
/// Base class for OEmbed response.
/// </summary>
[DataContract]
public abstract class OEmbedResponseBase<T>
{
[DataMember(Name = "type")]
public string? Type { get; set; }
[DataMember(Name = "version")]
public string? Version { get; set; }
[DataMember(Name = "title")]
public string? Title { get; set; }
[DataMember(Name = "author_name")]
public string? AuthorName { get; set; }
[DataMember(Name = "author_url")]
public string? AuthorUrl { get; set; }
[DataMember(Name = "provider_name")]
public string? ProviderName { get; set; }
[DataMember(Name = "provider_url")]
public string? ProviderUrl { get; set; }
[DataMember(Name = "thumbnail_url")]
public string? ThumbnailUrl { get; set; }
[DataMember(Name = "thumbnail_height")]
public T? ThumbnailHeight { get; set; }
[DataMember(Name = "thumbnail_width")]
public T? ThumbnailWidth { get; set; }
[DataMember(Name = "html")]
public string? Html { get; set; }
[DataMember(Name = "url")]
public string? Url { get; set; }
[DataMember(Name = "height")]
public T? Height { get; set; }
[DataMember(Name = "width")]
public T? Width { get; set; }
/// <summary>
/// Gets the HTML.
/// </summary>
/// <returns>The response HTML</returns>
public string GetHtml()
{
if (Type == "photo")
{
return "<img src=\"" + Url + "\" width=\"" + Width + "\" height=\"" + Height + "\" alt=\"" +
WebUtility.HtmlEncode(Title) + "\" />";
}
return string.IsNullOrEmpty(Html) == false ? Html : string.Empty;
}
}

View File

@@ -0,0 +1,9 @@
using System.Runtime.Serialization;
namespace Umbraco.Cms.Core.Media.EmbedProviders;
/// <summary>
/// Wrapper class for OEmbed response with width and height as string values.
/// </summary>
[DataContract]
public class OEmbedResponseWithStringDimensions : OEmbedResponseBase<string>;