Skip to content

Commit

Permalink
mediaUrl portal function #10610
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Feb 5, 2025
1 parent 11726fb commit cdd9375
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public String createUrl()
.webRequest( this.requestSupplier.get() )
.build();

return this.urlServiceSupplier.get().attachmentMediaUrl( params );
return null;

// return this.urlServiceSupplier.get().attachmentMediaUrl( params );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public String createUrl()
.branch( this.branch )
.build();

return urlServiceSupplier.get().imageMediaUrl( imageMediaUrlParams );
return null;
// return urlServiceSupplier.get().imageMediaUrl( imageMediaUrlParams );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.enonic.xp.branch.Branch;
import com.enonic.xp.content.Media;
import com.enonic.xp.project.ProjectName;
import com.enonic.xp.site.Site;

public class ImageUrlGeneratorParams
{
Expand All @@ -15,8 +14,6 @@ public class ImageUrlGeneratorParams

public RewritePathStrategy rewritePathStrategy;

public Supplier<Site> nearestSiteProvider;

public Supplier<Media> mediaProvider;

public ProjectName projectName;
Expand All @@ -25,10 +22,6 @@ public class ImageUrlGeneratorParams

public String scale;

public String id;

public String path;

public String background;

public Integer quality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class ImageUrlParams

private String branch;

private String siteKey;
private String contentKey;

public String getId()
{
Expand Down Expand Up @@ -78,9 +78,9 @@ public String getBranch()
return branch;
}

public String getSiteKey()
public String getContentKey()
{
return siteKey;
return contentKey;
}

public ImageUrlParams id( final String value )
Expand Down Expand Up @@ -142,9 +142,9 @@ public ImageUrlParams branch( final String branch )
return this;
}

public ImageUrlParams siteKey( final String siteKey )
public ImageUrlParams contentKey( final String contentKey )
{
this.siteKey = siteKey;
this.contentKey = contentKey;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ public interface PortalUrlService

String apiUrl( ApiUrlParams params );

String imageMediaUrl( ImageMediaUrlParams params );

String attachmentMediaUrl( AttachmentMediaUrlParams params );

String imageUrl( ImageUrlGeneratorParams params );
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.enonic.xp.portal.url;

import com.enonic.xp.branch.Branch;
import com.enonic.xp.content.Content;
import com.enonic.xp.portal.PortalRequest;
import com.enonic.xp.project.ProjectName;

public interface UrlStrategyFacade
{
PathPrefixStrategy requestPathPrefixStrategy( final PortalRequest portalRequest );

PathPrefixStrategy contextPathPrefixStrategy( final ProjectName projectName,
final Branch branch, final String contentKey );

BaseUrlStrategy offlineBaseUrlStrategy( final ProjectName projectName, final Branch branch, final String siteKey );
BaseUrlStrategy offlineBaseUrlStrategy( final ProjectName projectName, final Branch branch, final Content content );

BaseUrlStrategy requestBaseUrlStrategy( final PortalRequest portalRequest, final String urlType );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ else if ( requestURI.startsWith( WEBAPP_PREFIX ) )
result.setBaseUri( WEBAPP_PREFIX + matcher.group( 0 ) );
}
}
else if ( requestURI.startsWith( "/api/" ) )
{
result.setBaseUri( "/api" );
}
}

private static String subPath( String requestURI, String prefix )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.enonic.xp.context.ContextAccessor;
import com.enonic.xp.context.ContextBuilder;
import com.enonic.xp.macro.MacroService;
import com.enonic.xp.portal.PortalRequest;
import com.enonic.xp.portal.PortalRequestAccessor;
import com.enonic.xp.portal.impl.PortalConfig;
import com.enonic.xp.portal.impl.RedirectChecksumService;
import com.enonic.xp.portal.impl.url3.MediaService;
import com.enonic.xp.portal.impl.url3.UrlGenerator;
import com.enonic.xp.portal.impl.url3.UrlService;
import com.enonic.xp.portal.url.AbstractUrlParams;
import com.enonic.xp.portal.url.ApiUrlParams;
Expand All @@ -26,13 +26,13 @@
import com.enonic.xp.portal.url.ComponentUrlParams;
import com.enonic.xp.portal.url.GenerateUrlParams;
import com.enonic.xp.portal.url.IdentityUrlParams;
import com.enonic.xp.portal.url.ImageMediaUrlParams;
import com.enonic.xp.portal.url.ImageUrlGeneratorParams;
import com.enonic.xp.portal.url.ImageUrlParams;
import com.enonic.xp.portal.url.PageUrlParams;
import com.enonic.xp.portal.url.PortalUrlService;
import com.enonic.xp.portal.url.ProcessHtmlParams;
import com.enonic.xp.portal.url.ServiceUrlParams;
import com.enonic.xp.portal.url.UrlStrategyFacade;
import com.enonic.xp.resource.ResourceService;
import com.enonic.xp.security.RoleKeys;
import com.enonic.xp.security.auth.AuthenticationInfo;
Expand All @@ -52,7 +52,7 @@ public final class PortalUrlServiceImpl

private final RedirectChecksumService redirectChecksumService;

private final MediaService mediaService;
private final UrlStrategyFacade urlStrategyFacade;

private volatile boolean legacyImageServiceEnabled;

Expand All @@ -65,14 +65,15 @@ public final class PortalUrlServiceImpl
@Activate
public PortalUrlServiceImpl( @Reference final ContentService contentService, @Reference final ResourceService resourceService,
@Reference final MacroService macroService, @Reference final StyleDescriptorService styleDescriptorService,
@Reference final RedirectChecksumService redirectChecksumService, @Reference final MediaService mediaService )
@Reference final RedirectChecksumService redirectChecksumService,
@Reference final UrlStrategyFacade urlStrategyFacade )
{
this.contentService = contentService;
this.resourceService = resourceService;
this.macroService = macroService;
this.styleDescriptorService = styleDescriptorService;
this.redirectChecksumService = redirectChecksumService;
this.mediaService = mediaService;
this.urlStrategyFacade = urlStrategyFacade;
}

@Activate
Expand Down Expand Up @@ -122,24 +123,13 @@ public String imageUrl( final ImageUrlParams params )
}
else
{
final ImageMediaUrlParams imageMediaUrlParams = ImageMediaUrlParams.create()
.contentId( params.getId() )
.contentPath( params.getPath() )
.contextPathType( params.getContextPathType() )
.webRequest( params.getPortalRequest() )
.urlType( params.getType() )
.addQueryParams( params.getParams() )
.background( params.getBackground() )
.scale( params.getScale() )
.filter( params.getFilter() )
.quality( params.getQuality() )
.format( params.getFormat() )
.projectName( null )
.branch( null )
.siteKey( null )
.build();

return imageMediaUrl( imageMediaUrlParams );
final PortalRequest portalRequest = PortalRequestAccessor.get();

final ImageUrlGeneratorParams generatorParams = portalRequest == null
? urlStrategyFacade.offlineImageUrlParams( params )
: urlStrategyFacade.requestImageUrlParams( params );

return imageUrl( generatorParams );
}
}

Expand All @@ -154,21 +144,23 @@ public String attachmentUrl( final AttachmentUrlParams params )
}
else
{
final AttachmentMediaUrlParams attachmentMediaUrlParams = AttachmentMediaUrlParams.create()
.contentId( params.getId() )
.contentPath( params.getPath() )
.contextPathType( params.getContextPathType() )
.urlType( params.getType() )
.webRequest( params.getPortalRequest() )
.addQueryParams( params.getParams() )
.download( params.isDownload() )
.name( params.getName() )
.label( params.getLabel() )
.projectName( null )
.branch( null )
.build();

return attachmentMediaUrl( attachmentMediaUrlParams );
// final AttachmentMediaUrlParams attachmentMediaUrlParams = AttachmentMediaUrlParams.create()
// .contentId( params.getId() )
// .contentPath( params.getPath() )
// .contextPathType( params.getContextPathType() )
// .urlType( params.getType() )
// .webRequest( params.getPortalRequest() )
// .addQueryParams( params.getParams() )
// .download( params.isDownload() )
// .name( params.getName() )
// .label( params.getLabel() )
// .projectName( null )
// .branch( null )
// .build();
//
// return attachmentMediaUrl( attachmentMediaUrlParams );

return "";
}
}

Expand Down Expand Up @@ -210,19 +202,6 @@ public String apiUrl( final ApiUrlParams params )
}
}

@Override
public String imageMediaUrl( final ImageMediaUrlParams params )
{
return runWithAdminRole( () -> mediaService.imageMediaUrl( params ) );
}

@Override
public String attachmentMediaUrl( final AttachmentMediaUrlParams params )
{
return null;
// return runWithAdminRole( () -> mediaService.imageMediaUrl( params ) );
}

@Override
public String imageUrl( final ImageUrlGeneratorParams params )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,4 @@ public String imageUrl( com.enonic.xp.portal.url.ImageUrlGeneratorParams params
return UrlGenerator.generateUrl( baseUrlStrategy, mediaPathStrategy, rewritePathStrategy );
}

private ImageMediaPathStrategyParams map( final ImageUrlGeneratorParams source )
{
return ImageMediaPathStrategyParams.create()
.setMedia( source.getMedia() )
.setProjectName( source.getProjectName() )
.setBranch( source.getBranch() )
.setScale( source.getScale() )
.build();
}

}
Loading

0 comments on commit cdd9375

Please sign in to comment.