Merge branch 'U4-7312-2' of https://github.com/Phosworks/Umbraco-CMS into Phosworks-U4-7312-2
This commit is contained in:
@@ -144,31 +144,28 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag
|
||||
};
|
||||
angular.module("umbraco")
|
||||
.controller('Umbraco.PropertyEditors.FileUploadController', fileUploadController)
|
||||
.run(function(mediaHelper, umbRequestHelper){
|
||||
.run(function(mediaHelper, umbRequestHelper, assetsService){
|
||||
if (mediaHelper && mediaHelper.registerFileResolver) {
|
||||
|
||||
//NOTE: The 'entity' can be either a normal media entity or an "entity" returned from the entityResource
|
||||
// they contain different data structures so if we need to query against it we need to be aware of this.
|
||||
mediaHelper.registerFileResolver("Umbraco.UploadField", function(property, entity, thumbnail){
|
||||
if (thumbnail) {
|
||||
|
||||
if (mediaHelper.detectIfImageByExtension(property.value)) {
|
||||
|
||||
var thumbnailUrl = umbRequestHelper.getApiUrl(
|
||||
"imagesApiBaseUrl",
|
||||
"GetBigThumbnail",
|
||||
[{ originalImagePath: property.value }]);
|
||||
|
||||
return thumbnailUrl;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
assetsService.load(["lib/moment/moment-with-locales.js"]).then(
|
||||
function () {
|
||||
//NOTE: The 'entity' can be either a normal media entity or an "entity" returned from the entityResource
|
||||
// they contain different data structures so if we need to query against it we need to be aware of this.
|
||||
mediaHelper.registerFileResolver("Umbraco.UploadField", function(property, entity, thumbnail){
|
||||
if (thumbnail) {
|
||||
if (mediaHelper.detectIfImageByExtension(property.value)) {
|
||||
//get default big thumbnail from image processor
|
||||
var thumbnailUrl = property.value + "?rnd=" + moment(entity.updateDate).format("YYYYMMDDHHmmss") + "&width=500";
|
||||
return thumbnailUrl;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return property.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return property.value;
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,8 +104,6 @@ namespace Umbraco.Web.Editors
|
||||
return GetResized(imagePath, width, Convert.ToString(width));
|
||||
}
|
||||
|
||||
//TODO: We should delegate this to ImageProcessing
|
||||
|
||||
/// <summary>
|
||||
/// Gets a resized image - if the requested max width is greater than the original image, only the original image will be returned.
|
||||
/// </summary>
|
||||
@@ -124,53 +122,11 @@ namespace Umbraco.Web.Editors
|
||||
return Request.CreateResponse(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
var thumbFilePath = imagePath.TrimEnd(ext) + "_" + suffix + ext;
|
||||
var fullOrgPath = mediaFileSystem.GetFullPath(mediaFileSystem.GetRelativePath(imagePath));
|
||||
var fullNewPath = mediaFileSystem.GetFullPath(mediaFileSystem.GetRelativePath(thumbFilePath));
|
||||
var thumbIsNew = mediaFileSystem.FileExists(fullNewPath) == false;
|
||||
if (thumbIsNew)
|
||||
{
|
||||
//we need to generate it
|
||||
if (mediaFileSystem.FileExists(fullOrgPath) == false)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
using (var fileStream = mediaFileSystem.OpenFile(fullOrgPath))
|
||||
{
|
||||
if (fileStream.CanSeek) fileStream.Seek(0, 0);
|
||||
using (var originalImage = Image.FromStream(fileStream))
|
||||
{
|
||||
//If it is bigger, then do the resize
|
||||
if (originalImage.Width >= width && originalImage.Height >= width)
|
||||
{
|
||||
ImageHelper.GenerateThumbnail(
|
||||
originalImage,
|
||||
width,
|
||||
fullNewPath,
|
||||
ext.Replace(".", ""),
|
||||
mediaFileSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
//just return the original image
|
||||
fullNewPath = fullOrgPath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result = Request.CreateResponse(HttpStatusCode.OK);
|
||||
//NOTE: That we are not closing this stream as the framework will do that for us, if we try it will
|
||||
// fail. See http://stackoverflow.com/questions/9541351/returning-binary-file-from-controller-in-asp-net-web-api
|
||||
var stream = mediaFileSystem.OpenFile(fullNewPath);
|
||||
if (stream.CanSeek) stream.Seek(0, 0);
|
||||
result.Content = new StreamContent(stream);
|
||||
result.Headers.Date = mediaFileSystem.GetLastModified(imagePath);
|
||||
result.Content.Headers.ContentType = new MediaTypeHeaderValue(System.Web.MimeMapping.GetMimeMapping(imagePath));
|
||||
|
||||
return result;
|
||||
//redirect to ImageProcessor thumbnail with rnd generated from last modified time of original media file
|
||||
var response = Request.CreateResponse( HttpStatusCode.Found );
|
||||
var imageLastModified = mediaFileSystem.GetLastModified( imagePath );
|
||||
response.Headers.Location = new Uri( string.Format( "{0}?rnd={1}&width={2}", imagePath, string.Format( "{0:yyyyMMddHHmmss}", imageLastModified ), width ), UriKind.Relative );
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,29 +128,6 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
var umbracoFile = UmbracoMediaFile.Save(fileStream, fileName);
|
||||
|
||||
if (umbracoFile.SupportsResizing)
|
||||
{
|
||||
var additionalSizes = new List<int>();
|
||||
//get the pre-vals value
|
||||
var thumbs = editorValue.PreValues.FormatAsDictionary();
|
||||
if (thumbs.Any())
|
||||
{
|
||||
var thumbnailSizes = thumbs.First().Value.Value;
|
||||
// additional thumbnails configured as prevalues on the DataType
|
||||
foreach (var thumb in thumbnailSizes.Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
int thumbSize;
|
||||
if (thumb == "" || int.TryParse(thumb, out thumbSize) == false) continue;
|
||||
additionalSizes.Add(thumbSize);
|
||||
}
|
||||
}
|
||||
|
||||
using (var image = Image.FromStream(fileStream))
|
||||
{
|
||||
ImageHelper.GenerateMediaThumbnails(fs, fileName, umbracoFile.Extension, image, additionalSizes);
|
||||
}
|
||||
|
||||
}
|
||||
newValue.Add(umbracoFile.Url);
|
||||
//add to the saved paths
|
||||
savedFilePaths.Add(umbracoFile.Url);
|
||||
|
||||
Reference in New Issue
Block a user