// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System.ComponentModel.DataAnnotations; using System.Text; using Squidex.Domain.Apps.Core.Rules.Deprecated; using Squidex.Flows; using Squidex.Flows.Steps.Utils; using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Validation; namespace Squidex.Extensions.Actions.Prerender; [FlowStep( Title = "Prerender", IconImage = "", IconColor = "#2c3e50", Display = "Recache URL", Description = "Prerender a javascript website for bots.", ReadMore = "https://prerender.io")] #pragma warning disable CS0618 // Type or member is obsolete public sealed record PrerenderFlowStep : FlowStep, IConvertibleToAction #pragma warning restore CS0618 // Type or member is obsolete { [LocalizedRequired] [Display(Name = "Token", Description = "The prerender token from your account.")] [Editor(FlowStepEditor.Text)] [Expression] public string Token { get; set; } [LocalizedRequired] [Display(Name = "Url", Description = "The url to recache.")] [Editor(FlowStepEditor.Text)] [Expression] public string Url { get; set; } public override async ValueTask ExecuteAsync(FlowExecutionContext executionContext, CancellationToken ct) { var requestObject = new { prerenderToken = Token, Url }; var requestBody = executionContext.SerializeJson(requestObject); var request = new HttpRequestMessage(HttpMethod.Post, "/recache") { Content = new StringContent(requestBody, Encoding.UTF8, "application/json"), }; if (executionContext.IsSimulation) { executionContext.LogSkipSimulation( HttpDumpFormatter.BuildDump(request, null, null)); return Next(); } var httpClient = executionContext.Resolve() .CreateClient("Prerender"); var (_, dump) = await httpClient.SendAsync(executionContext, request, requestBody, ct); executionContext.Log("Success", dump); return Next(); } #pragma warning disable CS0618 // Type or member is obsolete public RuleAction ToAction() { return SimpleMapper.Map(this, new PrerenderAction()); } #pragma warning restore CS0618 // Type or member is obsolete }