TkEndpointController.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(accountId, endpoint, TimeSpan.FromSeconds(durationSeconds), TkEndpointManager.SuspendReason.Active, notifyOtherNodes: false);
  47. }
  48. else
  49. {
  50. await TkEndpointManager.SuspendAsync(accountId, endpoint, TkEndpointManager.SuspendReason.Active, notifyOtherNodes: false);
  51. }
  52. }
  53. return new APIResult(new
  54. {
  55. success = true,
  56. action = release ? "ReleaseSuspend" : "Suspend",
  57. });
  58. }
  59. [HttpPost]
  60. public async Task<ActionResult> GetStatus([FromForm] JsonElement body)
  61. {
  62. var ids = body.PathReadArray<int>("accountId[]");
  63. var result = await TkEndpointManager.GetStatus(ids);
  64. return new APIResult(new
  65. {
  66. success = true,
  67. data = result
  68. });
  69. }
  70. }
  71. }