88using Umbraco . Cms . Core . Models . DeliveryApi ;
99using Umbraco . Cms . Core . Models . PublishedContent ;
1010using Umbraco . Cms . Core . Services ;
11- using Umbraco . Extensions ;
1211
1312namespace Umbraco . Cms . Api . Delivery . Controllers . Content ;
1413
1514[ ApiVersion ( "1.0" ) ]
1615[ ApiVersion ( "2.0" ) ]
1716public class ByRouteContentApiController : ContentApiItemControllerBase
1817{
19- private readonly IRequestRoutingService _requestRoutingService ;
18+ private readonly IApiContentPathResolver _apiContentPathResolver ;
2019 private readonly IRequestRedirectService _requestRedirectService ;
2120 private readonly IRequestPreviewService _requestPreviewService ;
2221 private readonly IRequestMemberAccessService _requestMemberAccessService ;
22+ private const string PreviewContentRequestPathPrefix = $ "/{ Constants . DeliveryApi . Routing . PreviewContentPathPrefix } ";
2323
2424 [ Obsolete ( $ "Please use the constructor that does not accept { nameof ( IPublicAccessService ) } . Will be removed in V14.") ]
2525 public ByRouteContentApiController (
@@ -58,20 +58,58 @@ public ByRouteContentApiController(
5858 {
5959 }
6060
61- [ ActivatorUtilitiesConstructor ]
61+ [ Obsolete ( $ "Please use the constructor that accepts { nameof ( IApiContentPathResolver ) } . Will be removed in V15." ) ]
6262 public ByRouteContentApiController (
6363 IApiPublishedContentCache apiPublishedContentCache ,
6464 IApiContentResponseBuilder apiContentResponseBuilder ,
6565 IRequestRoutingService requestRoutingService ,
6666 IRequestRedirectService requestRedirectService ,
6767 IRequestPreviewService requestPreviewService ,
6868 IRequestMemberAccessService requestMemberAccessService )
69+ : this (
70+ apiPublishedContentCache ,
71+ apiContentResponseBuilder ,
72+ requestRedirectService ,
73+ requestPreviewService ,
74+ requestMemberAccessService ,
75+ StaticServiceProvider . Instance . GetRequiredService < IApiContentPathResolver > ( ) )
76+ {
77+ }
78+
79+ [ Obsolete ( $ "Please use the non-obsolete constructor. Will be removed in V15.") ]
80+ public ByRouteContentApiController (
81+ IApiPublishedContentCache apiPublishedContentCache ,
82+ IApiContentResponseBuilder apiContentResponseBuilder ,
83+ IPublicAccessService publicAccessService ,
84+ IRequestRoutingService requestRoutingService ,
85+ IRequestRedirectService requestRedirectService ,
86+ IRequestPreviewService requestPreviewService ,
87+ IRequestMemberAccessService requestMemberAccessService ,
88+ IApiContentPathResolver apiContentPathResolver )
89+ : this (
90+ apiPublishedContentCache ,
91+ apiContentResponseBuilder ,
92+ requestRedirectService ,
93+ requestPreviewService ,
94+ requestMemberAccessService ,
95+ apiContentPathResolver )
96+ {
97+ }
98+
99+ [ ActivatorUtilitiesConstructor ]
100+ public ByRouteContentApiController (
101+ IApiPublishedContentCache apiPublishedContentCache ,
102+ IApiContentResponseBuilder apiContentResponseBuilder ,
103+ IRequestRedirectService requestRedirectService ,
104+ IRequestPreviewService requestPreviewService ,
105+ IRequestMemberAccessService requestMemberAccessService ,
106+ IApiContentPathResolver apiContentPathResolver )
69107 : base ( apiPublishedContentCache , apiContentResponseBuilder )
70108 {
71- _requestRoutingService = requestRoutingService ;
72109 _requestRedirectService = requestRedirectService ;
73110 _requestPreviewService = requestPreviewService ;
74111 _requestMemberAccessService = requestMemberAccessService ;
112+ _apiContentPathResolver = apiContentPathResolver ;
75113 }
76114
77115 [ HttpGet ( "item/{*path}" ) ]
@@ -105,8 +143,6 @@ public async Task<IActionResult> ByRouteV20(string path = "")
105143 private async Task < IActionResult > HandleRequest ( string path )
106144 {
107145 path = DecodePath ( path ) ;
108-
109- path = path . TrimStart ( "/" ) ;
110146 path = path . Length == 0 ? "/" : path ;
111147
112148 IPublishedContent ? contentItem = GetContent ( path ) ;
@@ -128,17 +164,12 @@ private async Task<IActionResult> HandleRequest(string path)
128164 }
129165
130166 private IPublishedContent ? GetContent ( string path )
131- => path . StartsWith ( Constants . DeliveryApi . Routing . PreviewContentPathPrefix )
167+ => path . StartsWith ( PreviewContentRequestPathPrefix )
132168 ? GetPreviewContent ( path )
133169 : GetPublishedContent ( path ) ;
134170
135171 private IPublishedContent ? GetPublishedContent ( string path )
136- {
137- var contentRoute = _requestRoutingService . GetContentRoute ( path ) ;
138-
139- IPublishedContent ? contentItem = ApiPublishedContentCache . GetByRoute ( contentRoute ) ;
140- return contentItem ;
141- }
172+ => _apiContentPathResolver . ResolveContentPath ( path ) ;
142173
143174 private IPublishedContent ? GetPreviewContent ( string path )
144175 {
@@ -147,7 +178,7 @@ private async Task<IActionResult> HandleRequest(string path)
147178 return null ;
148179 }
149180
150- if ( Guid . TryParse ( path . AsSpan ( Constants . DeliveryApi . Routing . PreviewContentPathPrefix . Length ) . TrimEnd ( "/" ) , out Guid contentId ) is false )
181+ if ( Guid . TryParse ( path . AsSpan ( PreviewContentRequestPathPrefix . Length ) . TrimEnd ( "/" ) , out Guid contentId ) is false )
151182 {
152183 return null ;
153184 }
0 commit comments