Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Core.Services.OperationStatus;

namespace Umbraco.Cms.Api.Management.Controllers.OEmbed;

[VersionedApiBackOfficeRoute("oembed")]
[ApiExplorerSettings(GroupName = "oEmbed")]
public abstract class OEmbedControllerBase : ManagementApiControllerBase
{
protected IActionResult OEmbedOperationStatusResult(OEmbedOperationStatus status)
=> OperationStatusResult(status, problemDetailsBuilder => status switch
{
OEmbedOperationStatus.NoSupportedProvider => BadRequest(problemDetailsBuilder
.WithTitle("The specified url is not supported.")
.WithDetail("No oEmbed provider was found for the specified url.")
.Build()),
_ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder
.WithTitle("Unknown oEmbed operation status.")
.Build()),
});

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.OEmbed;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Web.Common.Authorization;

namespace Umbraco.Cms.Api.Management.Controllers.OEmbed;

[Authorize(Policy = AuthorizationPolicies.SectionAccessContent)]
[ApiVersion("1.0")]
public class QueryOEmbedController : OEmbedControllerBase
{
private readonly IOEmbedService _oEmbedService;

public QueryOEmbedController(IOEmbedService oEmbedService)
{
_oEmbedService = oEmbedService;
}

[HttpGet("query")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(OEmbedResponseModel), StatusCodes.Status200OK)]
public async Task<IActionResult> Query(CancellationToken cancellationToken, Uri url, int? maxWidth = null, int? maxHeight = null)
{
Attempt<string, OEmbedOperationStatus> result = await _oEmbedService.GetMarkupAsync(url, maxWidth, maxHeight, cancellationToken);

return result.Success
? Ok(new OEmbedResponseModel() { Markup = result.Result })
: OEmbedOperationStatusResult(result.Status);
}
}
133 changes: 133 additions & 0 deletions src/Umbraco.Cms.Api.Management/OpenApi.json
Original file line number Diff line number Diff line change
Expand Up @@ -8331,6 +8331,20 @@
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/PublicAccessResponseModel"
}
]
}
}
}
},
"404": {
"description": "Not Found",
"content": {
Expand Down Expand Up @@ -19479,6 +19493,67 @@
]
}
},
"/umbraco/management/api/v1/oembed/query": {
"get": {
"tags": [
"oEmbed"
],
"operationId": "GetOembedQuery",
"parameters": [
{
"name": "url",
"in": "query",
"schema": {
"type": "string",
"format": "uri"
}
},
{
"name": "maxWidth",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "maxHeight",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/OEmbedResponseModel"
}
]
}
}
}
},
"401": {
"description": "The resource is protected and requires an authentication token"
},
"403": {
"description": "The authenticated user do not have access to this resource"
}
},
"security": [
{
"Backoffice User": [ ]
}
]
}
},
"/umbraco/management/api/v1/package/{name}/run-migration": {
"post": {
"tags": [
Expand Down Expand Up @@ -38540,6 +38615,18 @@
},
"additionalProperties": false
},
"OEmbedResponseModel": {
"required": [
"markup"
],
"type": "object",
"properties": {
"markup": {
"type": "string"
}
},
"additionalProperties": false
},
"ObjectTypeResponseModel": {
"required": [
"id"
Expand Down Expand Up @@ -40394,6 +40481,52 @@
},
"additionalProperties": false
},
"PublicAccessResponseModel": {
"required": [
"errorDocument",
"groups",
"loginDocument",
"members"
],
"type": "object",
"properties": {
"loginDocument": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
]
},
"errorDocument": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
]
},
"members": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/MemberItemResponseModel"
}
]
}
},
"groups": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/MemberGroupItemResponseModel"
}
]
}
}
},
"additionalProperties": false
},
"PublishDocumentRequestModel": {
"required": [
"publishSchedules"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Umbraco.Cms.Api.Management.ViewModels.OEmbed;

public class OEmbedResponseModel
{
public required string Markup { get; set; }
}
1 change: 1 addition & 0 deletions src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private void AddCoreServices()
Services.AddUnique<ITemporaryFileService, TemporaryFileService>();
Services.AddUnique<ITemplateContentParserService, TemplateContentParserService>();
Services.AddUnique<IEntityService, EntityService>();
Services.AddUnique<IOEmbedService, OEmbedService>();
Services.AddUnique<IRelationService, RelationService>();
Services.AddUnique<IMemberTypeService, MemberTypeService>();
Services.AddUnique<IMemberContentEditingService, MemberContentEditingService>();
Expand Down
10 changes: 8 additions & 2 deletions src/Umbraco.Core/Media/EmbedProviders/DailyMotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public DailyMotion(IJsonSerializer jsonSerializer)
{ "format", "xml" },
};

public override string GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
XmlDocument xmlDocument = base.GetXmlResponse(requestUrl);
XmlDocument xmlDocument = await base.GetXmlResponseAsync(requestUrl, cancellationToken);

return GetXmlProperty(xmlDocument, "/oembed/html");
}

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}
}
10 changes: 8 additions & 2 deletions src/Umbraco.Core/Media/EmbedProviders/Flickr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ public Flickr(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

public override string GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
XmlDocument xmlDocument = base.GetXmlResponse(requestUrl);
XmlDocument xmlDocument = await base.GetXmlResponseAsync(requestUrl, cancellationToken);

var imageUrl = GetXmlProperty(xmlDocument, "/oembed/url");
var imageWidth = GetXmlProperty(xmlDocument, "/oembed/width");
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Media/EmbedProviders/GettyImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ public GettyImages(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
OEmbedResponse? oembed = base.GetJsonResponse<OEmbedResponse>(requestUrl);
OEmbedResponse? oembed = await base.GetJsonResponseAsync<OEmbedResponse>(requestUrl, cancellationToken);

return oembed?.GetHtml();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Media/EmbedProviders/Giphy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ public Giphy(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
OEmbedResponse? oembed = base.GetJsonResponse<OEmbedResponse>(requestUrl);
OEmbedResponse? oembed = await base.GetJsonResponseAsync<OEmbedResponse>(requestUrl, cancellationToken);

return oembed?.GetHtml();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Media/EmbedProviders/Hulu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ public Hulu(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
OEmbedResponse? oembed = base.GetJsonResponse<OEmbedResponse>(requestUrl);
OEmbedResponse? oembed = await base.GetJsonResponseAsync<OEmbedResponse>(requestUrl, cancellationToken);

return oembed?.GetHtml();
}
Expand Down
10 changes: 8 additions & 2 deletions src/Umbraco.Core/Media/EmbedProviders/Issuu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ public Issuu(IJsonSerializer jsonSerializer)
{ "format", "xml" },
};

public override string GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
XmlDocument xmlDocument = base.GetXmlResponse(requestUrl);
XmlDocument xmlDocument = await base.GetXmlResponseAsync(requestUrl, cancellationToken);

return GetXmlProperty(xmlDocument, "/oembed/html");
}
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Media/EmbedProviders/Kickstarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ public Kickstarter(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
OEmbedResponse? oembed = base.GetJsonResponse<OEmbedResponse>(requestUrl);
OEmbedResponse? oembed = await base.GetJsonResponseAsync<OEmbedResponse>(requestUrl, cancellationToken);

return oembed?.GetHtml();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Media/EmbedProviders/LottieFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ public LottieFiles(IJsonSerializer jsonSerializer)

public override Dictionary<string, string> RequestParams => new();

[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}

public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = this.GetEmbedProviderUrl(url, maxWidth, maxHeight);
OEmbedResponse? oembed = this.GetJsonResponse<OEmbedResponse>(requestUrl);
OEmbedResponse? oembed = await this.GetJsonResponseAsync<OEmbedResponse>(requestUrl, cancellationToken);
var html = oembed?.GetHtml();

// LottieFiles doesn't seem to support maxwidth and maxheight via oembed
Expand Down
Loading