https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6586 - Migrated ImagesController
This commit is contained in:
@@ -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
|
||||
/// <remarks>
|
||||
/// If there is no original image is found then this will return not found.
|
||||
/// </remarks>
|
||||
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
|
||||
/// <remarks>
|
||||
/// If there is no media, image property or image file is found then this will return not found.
|
||||
/// </remarks>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,10 +171,11 @@ namespace Umbraco.Web.Editors
|
||||
"mediaApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<MediaController>(
|
||||
controller => controller.GetRootMedia())
|
||||
},
|
||||
{
|
||||
"imagesApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<ImagesController>(
|
||||
controller => controller.GetBigThumbnail(""))
|
||||
},
|
||||
//TODO reintroduce
|
||||
// {
|
||||
// "imagesApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<ImagesController>(
|
||||
// controller => controller.GetBigThumbnail(""))
|
||||
// },
|
||||
{
|
||||
"sectionApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<SectionController>(
|
||||
controller => controller.GetSections())
|
||||
|
||||
@@ -346,7 +346,6 @@
|
||||
<Compile Include="Editors\Filters\ContentSaveValidationAttribute.cs" />
|
||||
<Compile Include="Editors\ContentTypeControllerBase.cs" />
|
||||
<Compile Include="Editors\DataTypeController.cs" />
|
||||
<Compile Include="Editors\ImagesController.cs" />
|
||||
<Compile Include="Editors\PackageInstallController.cs" />
|
||||
<Compile Include="Editors\RelationController.cs" />
|
||||
<Compile Include="GridTemplateExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user