| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using Admin.NET.Plugin.AiDOP.DataPlatform.Core;
- using Admin.NET.Plugin.AiDOP.DataPlatform.Core.Edge;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- namespace Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
- public sealed partial class MdpIngestDatasetController
- {
- [HttpGet("{id:long}/edge")]
- public Task<IActionResult> ListEdgeDevices(long id, long? factoryId) =>
- EdgeAction(id, factoryId, TrialPermission, async (service, scope) =>
- Ok(new { devices = await service.ListAsync(scope.TenantId, scope.FactoryId, id), canApprove = await Can(PublishPermission) }));
- [HttpPost("{id:long}/edge"), RequestSizeLimit(4096)]
- public Task<IActionResult> ApproveEdgeDevice(long id, long? factoryId, MdpEdgeApproveInput input) =>
- EdgeAction(id, factoryId, PublishPermission, async (service, scope) =>
- Ok(await service.ApproveAsync(scope.TenantId, scope.FactoryId, id, input.SourceId, input.Name, user.UserId)));
- [HttpPut("{id:long}/edge/{device:guid}/task"), RequestSizeLimit(98304)]
- public Task<IActionResult> ConfigureEdgeDevice(long id, Guid device, long? factoryId, MdpEdgeTaskInput input) =>
- EdgeAction(id, factoryId, PublishPermission, async (service, scope) =>
- {
- await service.ConfigureAsync(scope.TenantId, scope.FactoryId, id, device, user.UserId, input);
- return NoContent();
- });
- [HttpPost("{id:long}/edge/{device:guid}/recovery/preview"), RequestSizeLimit(4096)]
- public Task<IActionResult> PreviewEdgePage(long id, Guid device, long? factoryId, MdpEdgePagePreviewInput input) =>
- EdgeAction(id, factoryId, TrialPermission, async (service, scope) =>
- Ok(await service.PreviewPageAsync(scope.TenantId, scope.FactoryId, id, device, input)));
- [HttpPost("{id:long}/edge/{device:guid}/recovery"), RequestSizeLimit(4096)]
- public Task<IActionResult> RecoverEdgePage(long id, Guid device, long? factoryId, MdpEdgePageApproval input, CancellationToken token) =>
- EdgeAction(id, factoryId, PublishPermission, async (service, scope) =>
- {
- await service.RecoverPageAsync(scope.TenantId, scope.FactoryId, id, device, user.UserId, input, token);
- return NoContent();
- });
- [HttpPost("{id:long}/edge/{device:guid}/revoke")]
- public Task<IActionResult> RevokeEdgeDevice(long id, Guid device, long? factoryId) =>
- EdgeAction(id, factoryId, PublishPermission, async (service, scope) =>
- {
- await service.RevokeAsync(scope.TenantId, scope.FactoryId, id, device, user.UserId);
- return NoContent();
- });
- private Task<IActionResult> EdgeAction(long id, long? factoryId, string permission, Func<MdpEdgeDeviceService, DatasetScope, Task<IActionResult>> action)
- => WithScope(factoryId, async scope =>
- {
- if (!await Can(permission)) return Forbid();
- if (!await Datasets(scope).AnyAsync(row => row.Id == id)) return NotFound();
- Response.Headers.CacheControl = "no-store";
- try { return await action(HttpContext.RequestServices.GetRequiredService<MdpEdgeDeviceService>(), scope); }
- catch (Exception error) when (error is EdgeContractException or MdpIngestHttpException or IngestContractException
- or System.Data.Common.DbException or SqlSugarException)
- {
- return MdpEdgeDeviceController.EdgeFailure(error);
- }
- catch (Exception error) when (error is System.Text.Json.JsonException or ArgumentException or MdpApiPullException)
- {
- return BadRequest(new { code = "EDGE_TASK_INVALID" });
- }
- });
- }
- public sealed record MdpEdgeApproveInput(long SourceId, string Name);
|