From 0d65fccd52bbb241b3e84571a17fe14f6eca4a78 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 20 May 2020 13:51:21 +0200 Subject: [PATCH] https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6586 - Migrated ImagesController --- .../Controllers}/ImagesController.cs | 18 +++++++++--------- .../Editors/BackOfficeServerVariables.cs | 9 +++++---- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 3 files changed, 14 insertions(+), 14 deletions(-) rename src/{Umbraco.Web/Editors => Umbraco.Web.BackOffice/Controllers}/ImagesController.cs (91%) diff --git a/src/Umbraco.Web/Editors/ImagesController.cs b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs similarity index 91% rename from src/Umbraco.Web/Editors/ImagesController.cs rename to src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs index bbad627c3b..96eb120b25 100644 --- a/src/Umbraco.Web/Editors/ImagesController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs @@ -2,10 +2,13 @@ using System.IO; using System.Net; using System.Net.Http; +using Microsoft.AspNetCore.Mvc; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Media; using Umbraco.Core.Models; +using Umbraco.Web.BackOffice.Controllers; +using Umbraco.Web.Common.Attributes; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; @@ -36,10 +39,10 @@ namespace Umbraco.Web.Editors /// /// If there is no original image is found then this will return not found. /// - public HttpResponseMessage GetBigThumbnail(string originalImagePath) + public IActionResult GetBigThumbnail(string originalImagePath) { return string.IsNullOrWhiteSpace(originalImagePath) - ? Request.CreateResponse(HttpStatusCode.OK) + ? Ok() : GetResized(originalImagePath, 500); } @@ -52,22 +55,20 @@ namespace Umbraco.Web.Editors /// /// If there is no media, image property or image file is found then this will return not found. /// - public HttpResponseMessage GetResized(string imagePath, int width) + public IActionResult GetResized(string imagePath, int width) { var ext = Path.GetExtension(imagePath); // we need to check if it is an image by extension if (_contentSettings.IsImageFile(ext) == false) - return Request.CreateResponse(HttpStatusCode.NotFound); + return NotFound(); //redirect to ImageProcessor thumbnail with rnd generated from last modified time of original media file - var response = Request.CreateResponse(HttpStatusCode.Found); - DateTimeOffset? imageLastModified = null; try { imageLastModified = _mediaFileSystem.GetLastModified(imagePath); - + } catch (Exception) { @@ -80,8 +81,7 @@ namespace Umbraco.Web.Editors var rnd = imageLastModified.HasValue ? $"&rnd={imageLastModified:yyyyMMddHHmmss}" : null; var imageUrl = _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(imagePath) { UpScale = false, Width = width, AnimationProcessMode = "first", ImageCropMode = "max", CacheBusterValue = rnd }); - response.Headers.Location = new Uri(imageUrl, UriKind.RelativeOrAbsolute); - return response; + return new RedirectResult(imageUrl, false); } /// diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index edf50ba36b..33d4166112 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -171,10 +171,11 @@ namespace Umbraco.Web.Editors "mediaApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetRootMedia()) }, - { - "imagesApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetBigThumbnail("")) - }, + //TODO reintroduce + // { + // "imagesApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetBigThumbnail("")) + // }, { "sectionApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetSections()) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 99a165e6fd..434d5eda88 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -346,7 +346,6 @@ -