コード例 #1
0
        public OptimizeWaitResult SendToKrakenForCompression(Item currentItem)
        {
            var client  = new RestClient(ImageCompressionSettings.GetConversionApiEndpoint());
            var request = CreateUploadRequest(currentItem, client);

            client.Timeout = 300000;

            try
            {
                var response = client.Execute <OptimizeWaitResult>(request);
                var content  = response.Content;

                if (response.StatusCode != System.Net.HttpStatusCode.OK && response.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    Diagnostics.Log.Info(message: $"Image Upload failed {response.StatusCode} | response content: {response.Content}", owner: this);
                    ShouldContinue = false;
                    return(null);
                }

                if (response.Data != null && string.IsNullOrEmpty(response.Data.KrakedUrl))
                {
                    return(null);
                }

                Diagnostics.Log.Info(message: $"Image Uploaded to Tiny PNG {response.Data.KrakedUrl}", owner: this);

                return(response.Data);
            }
            catch (Exception ex)
            {
                Diagnostics.Log.Error(REMOTE_ERROR, ex);
                TinyPngApiGateway.RecordError(currentItem, ex.Message);
            }
            return(null);
        }
コード例 #2
0
        public string DownloadImage(MediaItem currentItem, OptimizeWaitResult img)
        {
            var client = new RestClient(img.KrakedUrl);

            var request = new RestRequest(Method.GET);

            request.AddHeader("Cache-Control", "no-cache");
            request.AddHeader("Accept", "*/*");
            client.Timeout = 300000;

            try
            {
                byte [] responseData = client.DownloadData(request);
                string  sizeBefore   = currentItem.InnerItem.Fields["Size"].Value;
                UpdateImageFile(currentItem, responseData);
                string sizeAfter = responseData.Length.ToString();
                TinyPngApiGateway.UpdateImageInformation(currentItem, sizeBefore, sizeAfter, ImageCompressionConstants.Messages.OPTIMISED_BY_KRAKEN, ImageCompressionSettings.GetConversionInformationField());
            }
            catch (Exception ex)
            {
                Diagnostics.Log.Error(TIMY_CONNETION_ERROR, ex);
                TinyPngApiGateway.RecordError(currentItem, ex.Message);
            }
            return("API ISSUE");
        }