using Microsoft.AspNetCore.Http; using Microsoft.IdentityModel.Tokens; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AipGateway.API.Application.Modules { public class GlobalConstants { public static readonly string API_ENDPOINT = "/aip-api"; public static readonly string API_GUID = "api-guid"; public static readonly string API_ID = "api-id"; public static readonly string API_KEY = "api-key"; public static readonly string API_REQUEST = "api-request"; public static readonly string API_RESULT = "api-result"; public static readonly int API_DB_RELOAD = 1; public static readonly int API_DB_LINKED_SYSTEMS = 3; public static readonly int API_DB_LINKED_SERVERS = 4; public static readonly int API_DB_LINKED_API_KEYS = 5; public static readonly int API_DB_LINKED_DECRYPT_KEYS = 6; public static readonly int API_AIP_DOWNLOAD = 10; public static readonly int API_AIP_LABELS = 11; public static readonly int API_AIP_POLICIES = 12; public static readonly int API_AIP_PROTECTIONS = 13; public static readonly int API_FILE_INFO = 21; public static readonly int API_FILE_SET_LABEL = 22; public static readonly int API_FILE_DELETE_LABEL = 23; public static readonly int API_FILE_SET_PROTECTION = 24; public static readonly int API_FILE_DELETE_PROTECTIN = 25; public static readonly int API_FILE_SET_LABEL_PROTECTION = 26; public static readonly int API_FILE_DELETE_LABEL_PROTECTION = 27; public static readonly int API_STREAM_INFO = 31; public static readonly int API_STREAM_SET_LABEL = 32; public static readonly int API_STREAM_DELETE_LABEL = 33; public static readonly int API_STREAM_SET_PROTECTION = 34; public static readonly int API_STREAM_DELETE_PROTECTIN = 35; public static readonly int API_STREAM_SET_LABEL_PROTECTION = 36; public static readonly int API_STREAM_DELETE_LABEL_PROTECTION = 37; public static readonly int API_DUMMY = 99; public static readonly int API_FILE_DATA = 13; public static readonly string API_RESULT_SUCCESS = "성공"; public static readonly string API_RESULT_FAIL = "실패"; public static readonly string API_RESULT_ERROR = "오류"; public static string GetApiGuid(HttpContext context) { string? guid = context.Items[API_GUID] as string; if (guid == null) { guid = Guid.NewGuid().ToString(); context.Items.Add(API_GUID, guid); } return guid; } public static void SetAuthorization(HttpContext context, int apiId, string apiKey) { context.Items[API_ID] = apiId.ToString(); context.Items[API_KEY] = apiKey; } public static int GetApiId(HttpContext context) { //int apiId = -1; string? temp = context.Items[API_ID] as string; if (temp == null) { return -1; } int.TryParse(temp, out int apiId); return apiId; } public static string GetApiKey(HttpContext context) { string? key = context.Items[API_KEY] as string; if (key == null) { key = "x"; } return key; } } }