TkEndpointController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. using System.Security.Cryptography;
  9. using Microsoft.AspNetCore.Authentication;
  10. using TencentCloud.Ecm.V20190719.Models;
  11. using COSXML.Network;
  12. using System.Linq;
  13. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  14. using TencentCloud.Lighthouse.V20200324.Models;
  15. using TencentCloud.Ame.V20190916.Models;
  16. using TencentCloud.Omics.V20221128.Models;
  17. using System.Threading.Channels;
  18. namespace molilian.api.Controllers
  19. {
  20. [ApiController]
  21. [Route("api/[controller]/[action]")]
  22. public class TkEndpointController : ControllerBase
  23. {
  24. protected IHttpContextAccessor _accessor;
  25. TaokeOpenCore core;
  26. public TkEndpointController(IHttpContextAccessor accessor)
  27. {
  28. _accessor = accessor;
  29. core = new TaokeOpenCore();
  30. }
  31. [HttpPost]
  32. public async Task<ActionResult> ChangeSuspend([FromForm] JsonElement body)
  33. {
  34. int accountId = body.Read<int>("accountId");
  35. string endpoint = body.Read<string>("endpoint");
  36. bool release = body.Read<bool>("release");
  37. int durationSeconds = body.Read<int>("durationSeconds");
  38. if (release)
  39. {
  40. TkEndpointManager.ReleaseSuspend(accountId, endpoint, notifyOtherNodes: false);
  41. }
  42. else
  43. {
  44. if (durationSeconds > 0)
  45. {
  46. await TkEndpointManager.SuspendForDurationAsync(
  47. accountId,
  48. endpoint,
  49. TimeSpan.FromSeconds(durationSeconds),
  50. TkEndpointManager.SuspendReason.Active,
  51. notifyOtherNodes: false,
  52. emitNotification: false);
  53. }
  54. else
  55. {
  56. await TkEndpointManager.SuspendAsync(accountId, endpoint, TkEndpointManager.SuspendReason.Active, notifyOtherNodes: false);
  57. }
  58. }
  59. return new APIResult(new
  60. {
  61. success = true,
  62. action = release ? "ReleaseSuspend" : "Suspend",
  63. });
  64. }
  65. [HttpPost]
  66. public async Task<ActionResult> GetStatus([FromForm] JsonElement body)
  67. {
  68. var ids = body.PathReadArray<int>("accountId[]");
  69. var result = await TkEndpointManager.GetStatus(ids);
  70. return new APIResult(new
  71. {
  72. success = true,
  73. data = result
  74. });
  75. }
  76. }
  77. }