V18 / 8d896b8a86e5
WebsitePreviewOperations.cs
Lilith/Core/Projects/WebsitePreviewOperations.cs
Unchanged from the preceding versionCS
using Lilith.Core.Commands;
namespace Lilith.Core.Projects;
internal static class WebsitePreviewOperations
{
internal static readonly string[] Names = ["project_preview_start_operation","project_preview_capture_operation"];
internal static Task<string> ExecuteAsync(ProviderClient provider,string name,IReadOnlyDictionary<string,string> inputs,CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
return name switch
{
"project_preview_start_operation" => Task.FromResult(provider.StartWebsitePreview(inputs.GetValueOrDefault("name", ""),inputs.GetValueOrDefault("draft_id", ""))),
"project_preview_capture_operation" => provider.CaptureStartedWebsiteAsync(ct),
_ => throw new ArgumentException("Unknown preview operation.")
};
}
}
public static class WebsitePreviewCommands
{
public static void Register(ChatCommandRegistry commands,Func<ProviderClient> provider) =>
commands.RegisterAsync("project-screenshots","Explicitly approve running one managed website to capture Desktop/Tablet/Mobile images: NAME [DRAFT_ID].",async c =>
{
var args = c.Arguments.Split(' ',StringSplitOptions.RemoveEmptyEntries);
if (args.Length is < 1 or > 2) throw new ArgumentException("Use /project-screenshots NAME [DRAFT_ID]. This executes that website's JavaScript.");
return new(true,await provider().CaptureWebsiteScreenshotsAsync(args[0],args.Length == 2 ? args[1] : "",c.CancellationToken));
});
}