From c19be0c64e0a5ce185e787d7770fc4e2c61c5dbd Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 23 Apr 2019 16:23:06 +0200 Subject: [PATCH] Misc cleanup --- .../Routing/DefaultMediaUrlProvider.cs | 17 +++++------------ src/Umbraco.Web/Routing/IMediaUrlProvider.cs | 2 +- src/Umbraco.Web/Routing/IUrlProvider.cs | 2 +- .../Routing/MediaUrlProviderCollection.cs | 3 +-- src/Umbraco.Web/Routing/UrlProvider.cs | 12 ++++++------ src/Umbraco.Web/UriUtility.cs | 9 +++++++++ 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs index 8616d2fc7f..a9c961c280 100644 --- a/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs @@ -22,8 +22,7 @@ namespace Umbraco.Web.Routing return null; } - var propType = content.ContentType.GetPropertyType(propertyAlias); - + var propType = prop.PropertyType; string path = null; switch (propType.EditorAlias) @@ -33,18 +32,12 @@ namespace Umbraco.Web.Routing break; case Constants.PropertyEditors.Aliases.ImageCropper: //get the url from the json format - - var stronglyTyped = value as ImageCropperValue; - if (stronglyTyped != null) - { - path = stronglyTyped.Src; - break; - } - path = value.ToString(); + path = value is ImageCropperValue stronglyTyped ? stronglyTyped.Src : value.ToString(); break; } - return path == null ? null : UrlInfo.Url(AssembleUrl(path, current, mode).ToString(), culture); + var url = AssembleUrl(path, current, mode); + return url == null ? null : UrlInfo.Url(url.ToString(), culture); } private Uri AssembleUrl(string path, Uri current, UrlProviderMode mode) @@ -70,7 +63,7 @@ namespace Umbraco.Web.Routing throw new ArgumentOutOfRangeException(nameof(mode)); } - return uri.Rewrite(UriUtility.ToAbsolute(uri.GetSafeAbsolutePath())); + return UriUtility.MediaUriFromUmbraco(uri); } } } diff --git a/src/Umbraco.Web/Routing/IMediaUrlProvider.cs b/src/Umbraco.Web/Routing/IMediaUrlProvider.cs index 00d0ea7ec7..419e4d78df 100644 --- a/src/Umbraco.Web/Routing/IMediaUrlProvider.cs +++ b/src/Umbraco.Web/Routing/IMediaUrlProvider.cs @@ -9,7 +9,7 @@ namespace Umbraco.Web.Routing public interface IMediaUrlProvider { /// - /// Gets the nice url of a media item. + /// Gets the url of a media item. /// /// The Umbraco context. /// The published content. diff --git a/src/Umbraco.Web/Routing/IUrlProvider.cs b/src/Umbraco.Web/Routing/IUrlProvider.cs index 55d39880d6..9459c2552d 100644 --- a/src/Umbraco.Web/Routing/IUrlProvider.cs +++ b/src/Umbraco.Web/Routing/IUrlProvider.cs @@ -10,7 +10,7 @@ namespace Umbraco.Web.Routing public interface IUrlProvider { /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The Umbraco context. /// The published content. diff --git a/src/Umbraco.Web/Routing/MediaUrlProviderCollection.cs b/src/Umbraco.Web/Routing/MediaUrlProviderCollection.cs index 7e2362c552..eef0cbd3bc 100644 --- a/src/Umbraco.Web/Routing/MediaUrlProviderCollection.cs +++ b/src/Umbraco.Web/Routing/MediaUrlProviderCollection.cs @@ -7,7 +7,6 @@ namespace Umbraco.Web.Routing { public MediaUrlProviderCollection(IEnumerable items) : base(items) - { - } + { } } } diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index 77f4a3c51a..525695c274 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -90,7 +90,7 @@ namespace Umbraco.Web.Routing => GetUrl(content, Mode, culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content. /// A value indicating whether the url should be absolute in any case. @@ -115,7 +115,7 @@ namespace Umbraco.Web.Routing => GetUrl(GetDocument(id), Mode, culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content identifier. /// A value indicating whether the url should be absolute in any case. @@ -130,7 +130,7 @@ namespace Umbraco.Web.Routing => GetUrl(GetDocument(id), GetMode(absolute), culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content identifier. /// The url mode. @@ -151,7 +151,7 @@ namespace Umbraco.Web.Routing => GetUrl(GetDocument(id), Mode, culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content identifier. /// A value indicating whether the url should be absolute in any case. @@ -166,7 +166,7 @@ namespace Umbraco.Web.Routing => GetUrl(GetDocument(id), GetMode(absolute), culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content identifier. /// The url mode. @@ -177,7 +177,7 @@ namespace Umbraco.Web.Routing => GetUrl(GetDocument(id), mode, culture, current); /// - /// Gets the nice url of a published content. + /// Gets the url of a published content. /// /// The published content. /// The url mode. diff --git a/src/Umbraco.Web/UriUtility.cs b/src/Umbraco.Web/UriUtility.cs index 04357a3a5a..9e94a4a20a 100644 --- a/src/Umbraco.Web/UriUtility.cs +++ b/src/Umbraco.Web/UriUtility.cs @@ -72,6 +72,15 @@ namespace Umbraco.Web return uri.Rewrite(path); } + // maps a media umbraco uri to a public uri + // ie with virtual directory - that is all for media + public static Uri MediaUriFromUmbraco(Uri uri) + { + var path = uri.GetSafeAbsolutePath(); + path = ToAbsolute(path); + return uri.Rewrite(path); + } + // maps a public uri to an internal umbraco uri // ie no virtual directory, no .aspx, lowercase... public static Uri UriToUmbraco(Uri uri)