| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Workflows.Management; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Export; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Exports the specified workflow definition as JSON download. |
| | | 10 | | /// </summary> |
| | | 11 | | [UsedImplicitly] |
| | 7 | 12 | | internal class Export(IWorkflowDefinitionExporter exporter) : ElsaEndpoint<Request> |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public override void Configure() |
| | | 16 | | { |
| | 3 | 17 | | Routes("/bulk-actions/export/workflow-definitions", "/workflow-definitions/{definitionId}/export"); |
| | 3 | 18 | | Verbs(FastEndpoints.Http.GET, FastEndpoints.Http.POST); |
| | 3 | 19 | | ConfigurePermissions("read:workflow-definitions"); |
| | 3 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 24 | | { |
| | 4 | 25 | | if (request.DefinitionId != null) |
| | | 26 | | { |
| | 2 | 27 | | var versionOptions = string.IsNullOrEmpty(request.VersionOptions) ? VersionOptions.Latest : VersionOptions.F |
| | 2 | 28 | | var result = await exporter.ExportAsync(request.DefinitionId, versionOptions, request.IncludeConsumingWorkfl |
| | | 29 | | |
| | 2 | 30 | | if (result == null) |
| | | 31 | | { |
| | 0 | 32 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 33 | | return; |
| | | 34 | | } |
| | | 35 | | |
| | 2 | 36 | | await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken); |
| | | 37 | | } |
| | 2 | 38 | | else if (request.Ids != null) |
| | | 39 | | { |
| | 2 | 40 | | var result = await exporter.ExportManyAsync(request.Ids, request.IncludeConsumingWorkflows, cancellationToke |
| | | 41 | | |
| | 2 | 42 | | if (result == null) |
| | | 43 | | { |
| | 0 | 44 | | await Send.NoContentAsync(cancellationToken); |
| | 0 | 45 | | return; |
| | | 46 | | } |
| | | 47 | | |
| | 2 | 48 | | await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken); |
| | | 49 | | } |
| | | 50 | | else |
| | | 51 | | { |
| | 0 | 52 | | await Send.NoContentAsync(cancellationToken); |
| | | 53 | | } |
| | 4 | 54 | | } |
| | | 55 | | } |