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 6, 2025
1 parent cdd9375 commit 4fc24ae
Show file tree
Hide file tree
Showing 33 changed files with 449 additions and 1,242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public final class ImageUrlHandler

private String scale;

private String projectName;

private String branch;

private String contentKey;

private boolean offline;

@Override
Expand Down Expand Up @@ -78,6 +84,21 @@ public void setScale( final String scale )
this.scale = scale;
}

public void setProjectName( final String projectName )
{
this.projectName = projectName;
}

public void setBranch( final String branch )
{
this.branch = branch;
}

public void setContentKey( final String contentKey )
{
this.contentKey = contentKey;
}

public void setOffline( final Boolean offline )
{
this.offline = Objects.requireNonNullElse( offline, false );
Expand All @@ -91,7 +112,10 @@ public String createUrl()
.quality( this.quality )
.filter( this.filter )
.format( this.format )
.scale( this.scale );
.scale( this.scale )
.projectName( this.projectName )
.branch( this.branch )
.contentKey( this.contentKey );

final ImageUrlGeneratorParams generatorParams = this.offline || this.request == null
? this.urlStrategyFacade.offlineImageUrlParams( params )
Expand Down
12 changes: 10 additions & 2 deletions modules/lib/lib-portal/src/main/resources/lib/xp/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type ImageUrlParams = IdXorPath & {
| 'full';
project?: string;
branch?: string;
contentKey?: string;
offline?: boolean | undefined;
};

Expand Down Expand Up @@ -119,6 +120,8 @@ interface ImageUrlHandler {

setOffline(value: boolean | undefined): void;

setContentKey(value?: string | null): void;

createUrl(): string;
}

Expand All @@ -136,6 +139,10 @@ interface ImageUrlHandler {
* @param {string} [params.format] Format of the image.
* @param {string} [params.filter] A number of filters are available to alter the image appearance, for example, blur(3), grayscale(), rounded(5), etc.
* @param {string} [params.type=server] URL type. Either `server` (server-relative URL) or `absolute`.
* @param {string} [params.projectName] Name of the project.
* @param {string} [params.branch] Name of the branch.
* @param {string} [params.contentKey] Key of the content.
* @param {boolean} [params.offline] Set to true if the URL should be generated without context of the current request.
* @param {object} [params.params] Custom parameters to append to the url.
*
* @returns {string} The generated URL.
Expand All @@ -147,13 +154,14 @@ export function imageUrl(params: ImageUrlParams): string {
bean.setPath(params.path);
bean.setUrlType(params.type);
// bean.setQueryParams(__.toScriptValue(params.params));
bean.setProjectName(params.project);
bean.setBranch(params.branch);
bean.setBackground(params.background);
bean.setQuality(params.quality);
bean.setFilter(params.filter);
bean.setFormat(params.format);
bean.setScale(params.scale);
bean.setProjectName(params.project);
bean.setBranch(params.branch);
bean.setContentKey(params.contentKey);
bean.setOffline(params.offline);

return bean.createUrl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,203 @@
package com.enonic.xp.portal.url;

import java.util.function.Supplier;
import java.util.Objects;

import com.enonic.xp.branch.Branch;
import com.enonic.xp.content.Media;
import com.enonic.xp.project.ProjectName;

public class ImageUrlGeneratorParams
{
public BaseUrlStrategy baseUrlStrategy;
private final BaseUrlStrategy baseUrlStrategy;

public PathPrefixStrategy pathPrefixStrategy;
private final PathPrefixStrategy pathPrefixStrategy;

public RewritePathStrategy rewritePathStrategy;
private final RewritePathStrategy rewritePathStrategy;

public Supplier<Media> mediaProvider;
private final Media media;

public ProjectName projectName;
private final ProjectName projectName;

public Branch branch;
private final Branch branch;

public String scale;
private final String background;

public String background;
private final Integer quality;

public Integer quality;
private final String filter;

public String filter;
private final String format;

public String format;
private final String scale;

private ImageUrlGeneratorParams( final Builder builder )
{
this.baseUrlStrategy = Objects.requireNonNull( builder.baseUrlStrategy );
this.pathPrefixStrategy = Objects.requireNonNull( builder.pathPrefixStrategy );
this.rewritePathStrategy = Objects.requireNonNull( builder.rewritePathStrategy );
this.media = Objects.requireNonNull( builder.media );
this.projectName = Objects.requireNonNull( builder.projectName );
this.branch = Objects.requireNonNull( builder.branch );
this.scale = Objects.requireNonNull( builder.scale );
this.background = builder.background;
this.quality = builder.quality;
this.filter = builder.filter;
this.format = builder.format;
}

public BaseUrlStrategy getBaseUrlStrategy()
{
return baseUrlStrategy;
}

public PathPrefixStrategy getPathPrefixStrategy()
{
return pathPrefixStrategy;
}

public RewritePathStrategy getRewritePathStrategy()
{
return rewritePathStrategy;
}

public Media getMedia()
{
return media;
}

public ProjectName getProjectName()
{
return projectName;
}

public Branch getBranch()
{
return branch;
}

public String getBackground()
{
return background;
}

public Integer getQuality()
{
return quality;
}

public String getFilter()
{
return filter;
}

public String getFormat()
{
return format;
}

public String getScale()
{
return scale;
}

public static Builder create()
{
return new Builder();
}

public static class Builder
{
private BaseUrlStrategy baseUrlStrategy;

private PathPrefixStrategy pathPrefixStrategy;

private RewritePathStrategy rewritePathStrategy;

private Media media;

private ProjectName projectName;

private Branch branch;

private String background;

private Integer quality;

private String filter;

private String format;

private String scale;

public Builder setBaseUrlStrategy( final BaseUrlStrategy baseUrlStrategy )
{
this.baseUrlStrategy = baseUrlStrategy;
return this;
}

public Builder setPathPrefixStrategy( final PathPrefixStrategy pathPrefixStrategy )
{
this.pathPrefixStrategy = pathPrefixStrategy;
return this;
}

public Builder setRewritePathStrategy( final RewritePathStrategy rewritePathStrategy )
{
this.rewritePathStrategy = rewritePathStrategy;
return this;
}

public Builder setMedia( final Media media )
{
this.media = media;
return this;
}

public Builder setProjectName( final ProjectName projectName )
{
this.projectName = projectName;
return this;
}

public Builder setBranch( final Branch branch )
{
this.branch = branch;
return this;
}

public Builder setBackground( final String background )
{
this.background = background;
return this;
}

public Builder setQuality( final Integer quality )
{
this.quality = quality;
return this;
}

public Builder setFilter( final String filter )
{
this.filter = filter;
return this;
}

public Builder setFormat( final String format )
{
this.format = format;
return this;
}

public Builder setScale( final String scale )
{
this.scale = scale;
return this;
}

public ImageUrlGeneratorParams build()
{
return new ImageUrlGeneratorParams( this );
}
}
}
Loading

0 comments on commit 4fc24ae

Please sign in to comment.