Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob URIs #2026

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/sirius/biz/storage/layer2/URLBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,31 @@ public String buildImageURL() {
return safeBuildURL(IMAGE_FALLBACK_URI);
}

/**
* Builds the URL for {@linkplain sirius.web.templates.pdf.TagliatellePDFContentHandler embedding the blob into a
* PDF}. This is done via a special {@link sirius.biz.web.BlobPdfReplaceHandler blob://} URI.
* <p>
* If the image is not available, a {@linkplain #fallbackUri fallback} URI using the
* {@link sirius.web.templates.pdf.handlers.ResourcePdfReplaceHandler resource://} scheme is returned.
*
* @return a <tt>blob://</tt> URI, or a <tt>resource://</tt> URI pointing to a fallback image in case of errors
*/
public String buildUrlForEmbeddingIntoPdf() {
if (space == null || Strings.isEmpty(blobKey)) {
return "resource:/" + Optional.ofNullable(fallbackUri)
.filter(Strings::isFilled)
.map(string -> string.startsWith("assets/") ? '/' + string : string)
.filter(string -> string.startsWith("/assets/"))
.orElse(IMAGE_FALLBACK_URI);
}

StringBuilder builder = new StringBuilder("blob://").append(space.getName()).append('/').append(blobKey);
if (Strings.isFilled(variant)) {
builder.append('/').append(variant);
}
return builder.toString();
}

/**
* Determines if a conversion for the given variant is expected.
*
Expand Down