GlobalConstants.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.IdentityModel.Tokens;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace AipGateway.API.Application.Modules
  9. {
  10. public class GlobalConstants
  11. {
  12. public static readonly string API_ENDPOINT = "/aip-api";
  13. public static readonly string API_GUID = "api-guid";
  14. public static readonly string API_ID = "api-id";
  15. public static readonly string API_KEY = "api-key";
  16. public static readonly string API_REQUEST = "api-request";
  17. public static readonly string API_RESULT = "api-result";
  18. public static readonly int API_DB_RELOAD = 1;
  19. public static readonly int API_DB_LINKED_SYSTEMS = 3;
  20. public static readonly int API_DB_LINKED_SERVERS = 4;
  21. public static readonly int API_DB_LINKED_API_KEYS = 5;
  22. public static readonly int API_DB_LINKED_DECRYPT_KEYS = 6;
  23. public static readonly int API_AIP_DOWNLOAD = 10;
  24. public static readonly int API_AIP_LABELS = 11;
  25. public static readonly int API_AIP_POLICIES = 12;
  26. public static readonly int API_AIP_PROTECTIONS = 13;
  27. public static readonly int API_FILE_INFO = 21;
  28. public static readonly int API_FILE_SET_LABEL = 22;
  29. public static readonly int API_FILE_DELETE_LABEL = 23;
  30. public static readonly int API_FILE_SET_PROTECTION = 24;
  31. public static readonly int API_FILE_DELETE_PROTECTIN = 25;
  32. public static readonly int API_FILE_SET_LABEL_PROTECTION = 26;
  33. public static readonly int API_FILE_DELETE_LABEL_PROTECTION = 27;
  34. public static readonly int API_STREAM_INFO = 31;
  35. public static readonly int API_STREAM_SET_LABEL = 32;
  36. public static readonly int API_STREAM_DELETE_LABEL = 33;
  37. public static readonly int API_STREAM_SET_PROTECTION = 34;
  38. public static readonly int API_STREAM_DELETE_PROTECTIN = 35;
  39. public static readonly int API_STREAM_SET_LABEL_PROTECTION = 36;
  40. public static readonly int API_STREAM_DELETE_LABEL_PROTECTION = 37;
  41. public static readonly int API_DUMMY = 99;
  42. public static readonly int API_FILE_DATA = 13;
  43. public static readonly string API_RESULT_SUCCESS = "성공";
  44. public static readonly string API_RESULT_FAIL = "실패";
  45. public static readonly string API_RESULT_ERROR = "오류";
  46. public static string GetApiGuid(HttpContext context)
  47. {
  48. string? guid = context.Items[API_GUID] as string;
  49. if (guid == null)
  50. {
  51. guid = Guid.NewGuid().ToString();
  52. context.Items.Add(API_GUID, guid);
  53. }
  54. return guid;
  55. }
  56. public static void SetAuthorization(HttpContext context, int apiId, string apiKey)
  57. {
  58. context.Items[API_ID] = apiId.ToString();
  59. context.Items[API_KEY] = apiKey;
  60. }
  61. public static int GetApiId(HttpContext context)
  62. {
  63. //int apiId = -1;
  64. string? temp = context.Items[API_ID] as string;
  65. if (temp == null)
  66. {
  67. return -1;
  68. }
  69. int.TryParse(temp, out int apiId);
  70. return apiId;
  71. }
  72. public static string GetApiKey(HttpContext context)
  73. {
  74. string? key = context.Items[API_KEY] as string;
  75. if (key == null)
  76. {
  77. key = "x";
  78. }
  79. return key;
  80. }
  81. }
  82. }