Example #1
0
        public static async Task <IActionResult> GetCatalog([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            string customerid = req.Query["customerid"];

            customerid = customerid ?? "";
            string snocache = req.Query["cnocache"];
            bool   nocache  = false;

            if ((snocache ?? "").ToLower() == "true")
            {
                nocache = true;
            }

            string ClientIP = req.HttpContext.Connection.RemoteIpAddress.ToString();


            //if (!Base.ValidateIP(ClientIP))
            //{
            //    if (Environment.GetEnvironmentVariable("EnforceGetURL") == "true")
            //        return new OkObjectResult("[]");
            //}

            if (string.IsNullOrEmpty(Base.localURL))
            {
                Base.localURL = req.GetEncodedUrl().ToLower().Split("/rest/v2/getcatalog")[0];
            }

            if (customerid.ToLower() == "--new--")
            {
                JArray oRes    = Base.GetCatalog("", true);
                JArray jsorted = new JArray(oRes.OrderByDescending(x => (DateTimeOffset?)x["ModifyDate"]));
                JArray jTop    = JArray.FromObject(jsorted.Take(30));
                return(new OkObjectResult(jTop));
            }

            if (customerid.ToLower() == "--old--")
            {
                Base.ResetMemoryCache();
                JArray oRes    = Base.GetCatalog("");
                JArray jsorted = new JArray(oRes.OrderBy(x => (DateTimeOffset?)x["Timestamp"]));
                JArray jTop    = JArray.FromObject(jsorted.Take(30));
                return(new OkObjectResult(jTop));
            }

            Base.WriteLog($"Get Catalog", ClientIP, 1200, customerid);
            log.LogInformation("GetCatalog from ClientIP: " + ClientIP + " CustomerID: " + customerid);

            JArray aRes = Base.GetCatalog(customerid, nocache);

            //Cleanup
            foreach (JObject jObj in aRes)
            {
                //remove quality
                if (jObj["Quality"] != null)
                {
                    jObj.Remove("Quality");
                }

                //remove Image
                if (jObj["IconId"] != null)
                {
                    jObj.Remove("IconId");
                }

                //remove Image
                if (jObj["Image"] != null)
                {
                    jObj.Remove("Image");
                }
            }

            return(new OkObjectResult(aRes));
        }