mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
157 changed files with 485 additions and 518 deletions
@ -0,0 +1,30 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.ComponentModel.DataAnnotations; |
|||
using Squidex.Domain.Apps.Core.Rules; |
|||
|
|||
namespace Squidex.Extensions.Actions.Prerender |
|||
{ |
|||
[RuleActionHandler(typeof(PrerenderActionHandler))] |
|||
[RuleAction( |
|||
IconImage = "<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><path d='M2.073 17.984l8.646-5.36v-1.787L.356 17.325v1.318l10.363 6.488v-1.787zM29.927 17.984l-8.646-5.36v-1.787l10.363 6.488v1.318l-10.363 6.488v-1.787zM18.228 6.693l-6.276 19.426 1.656.548 6.276-19.426z'/></svg>", |
|||
IconColor = "#2c3e50", |
|||
Display = "Recache URL", |
|||
Description = "Create a status update at Tweet to a your user account.", |
|||
ReadMore = "https://prerender.io")] |
|||
public sealed class PrerenderAction : RuleAction |
|||
{ |
|||
[Required] |
|||
[Display(Name = "Token", Description = "The prerender token from your account.")] |
|||
public string Token { get; set; } |
|||
|
|||
[Required] |
|||
[Display(Name = "Url", Description = "The url to recache.")] |
|||
public string Url { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Net.Http; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Newtonsoft.Json.Linq; |
|||
using Squidex.Domain.Apps.Core.HandleRules; |
|||
using Squidex.Domain.Apps.Core.HandleRules.EnrichedEvents; |
|||
|
|||
namespace Squidex.Extensions.Actions.Prerender |
|||
{ |
|||
public sealed class PrerenderActionHandler : RuleActionHandler<PrerenderAction, PrerenderJob> |
|||
{ |
|||
private readonly IHttpClientFactory httpClientFactory; |
|||
|
|||
public PrerenderActionHandler(RuleEventFormatter formatter, IHttpClientFactory httpClientFactory) |
|||
: base(formatter) |
|||
{ |
|||
this.httpClientFactory = httpClientFactory; |
|||
} |
|||
|
|||
protected override (string Description, PrerenderJob Data) CreateJob(EnrichedEvent @event, PrerenderAction action) |
|||
{ |
|||
var url = Format(action.Url, @event); |
|||
|
|||
var request = |
|||
new JObject( |
|||
new JProperty("prerenderToken", action.Token), |
|||
new JProperty("url", url)); |
|||
|
|||
return ($"Recache {url}", new PrerenderJob { RequestBody = request.ToString() }); |
|||
} |
|||
|
|||
protected override async Task<(string Dump, Exception Exception)> ExecuteJobAsync(PrerenderJob job) |
|||
{ |
|||
using (var httpClient = httpClientFactory.CreateClient()) |
|||
{ |
|||
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.prerender.io/recache") |
|||
{ |
|||
Content = new StringContent(job.RequestBody, Encoding.UTF8, "application/json") |
|||
}; |
|||
|
|||
return await httpClient.OneWayRequestAsync(request, job.RequestBody); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public sealed class PrerenderJob |
|||
{ |
|||
public string RequestBody { get; set; } |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue