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

Update attachment permalink only when handler is available #6641

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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.core.attachment.AttachmentUtils;
import run.halo.app.core.attachment.ThumbnailService;
import run.halo.app.core.attachment.ThumbnailSize;
Expand All @@ -28,6 +27,7 @@
import run.halo.app.extension.controller.ControllerBuilder;
import run.halo.app.extension.controller.Reconciler;
import run.halo.app.extension.controller.Reconciler.Request;
import run.halo.app.extension.controller.RequeueException;

@Slf4j
@Component
Expand Down Expand Up @@ -57,18 +57,15 @@ public Result reconcile(Request request) {

var annotations = attachment.getMetadata().getAnnotations();
if (annotations != null) {
attachmentService.getPermalink(attachment)
var permalink = attachmentService.getPermalink(attachment)
.map(URI::toASCIIString)
.switchIfEmpty(Mono.fromSupplier(() -> {
// Only for back-compatibility
return annotations.get(Constant.EXTERNAL_LINK_ANNO_KEY);
}))
.doOnNext(permalink -> {
log.debug("Set permalink {} for attachment {}", permalink, request.name());
var status = nullSafeStatus(attachment);
status.setPermalink(permalink);
})
.blockOptional();
.blockOptional()
.orElseThrow(() -> new RequeueException(new Result(true, null),
"Attachment handler is unavailable, requeue the request"
));
log.debug("Set permalink {} for attachment {}", permalink, request.name());
var status = nullSafeStatus(attachment);
status.setPermalink(permalink);
}
var permalink = nullSafeStatus(attachment).getPermalink();
if (StringUtils.isNotBlank(permalink) && AttachmentUtils.isImage(attachment)) {
Expand Down
Loading