using Aip.Service.Models.Request; namespace Aip.Service.Repositories; public class GlobalConstants { public static readonly string API_PREFIX = "/api/v1"; public static readonly string API_AIP = API_PREFIX + "/aip"; public static readonly string API_DB = API_PREFIX + "/db"; public static readonly string API_FILE = API_PREFIX + "/file"; public static readonly string API_STREAM = API_PREFIX + "/stream"; public static readonly string API_IP_ADDRESS = "api-ip-address"; public static readonly string API_START_TM = "api-start-tm"; public static readonly string API_START_MILLISECONDS = "api-start-milliseconds"; 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_DECRYPT_KEY = "api-decrypt-key"; public static readonly string API_JOB_OWNER = "api-job-owner"; public static readonly string API_RESULT_CODE = "api-result-code"; public static readonly string API_RESULT_MESSAGE = "api-result-message"; 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_FILE_ENCRYPT = 28; public static readonly int API_FILE_DECRYPT = 29; public static readonly int API_FILE_SET_LABELS = 30; public static readonly int API_FILE_DELETE_LABELS = 31; public static readonly int API_STREAM_INFO = 41; public static readonly int API_STREAM_SET_LABEL = 42; public static readonly int API_STREAM_DELETE_LABEL = 43; public static readonly int API_STREAM_SET_PROTECTION = 44; public static readonly int API_STREAM_DELETE_PROTECTIN = 45; public static readonly int API_STREAM_SET_LABEL_PROTECTION = 46; public static readonly int API_STREAM_DELETE_LABEL_PROTECTION = 67; public static readonly int API_STREAM_ENCRYPT = 48; public static readonly int API_STREAM_DECRYPT = 49; public static readonly int API_STREAM_SET_LABELS = 50; public static readonly int API_STREAM_DELETE_LABELS = 51; public static readonly int API_DUMMY = 99; public static readonly int API_FILE_DATA = 13; public static readonly int API_RESULT_SUCCESS_CODE = 0; public static readonly string API_RESULT_SUCCESS = "Success"; public static readonly string API_RESULT_FAIL = "Fail"; public static readonly string API_RESULT_ERROR = "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, RequestBase? req) { context.Items[API_ID] = apiId.ToString(); context.Items[API_KEY] = apiKey; if (req != null) { context.Items[API_DECRYPT_KEY] = req.decryptKey; context.Items[API_JOB_OWNER] = req.email; req.apiGuid = GetApiGuid(context); } } public static string getAttributeStr(HttpContext context, string attribute) { string? value = context.Items[attribute] as string; if (value == null) { return ""; } return value; } public static int getAttributeInt(HttpContext context, string attribute) { if (context.Items.TryGetValue(attribute, out var value) && value is int numValue) { return numValue; } return -1; } public static long getAttributeLong(HttpContext context, string attribute) { if (context.Items.TryGetValue(attribute, out var value) && value is long numValue) { return numValue; } return -1; //string? value = context.Items[attribute] as string; //if (value == null) //{ // return -1; //} //long.TryParse(value, out long numValue); //return numValue; } 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; } }