From ba18f7010b3cd206b784018eae6093a71393fb24 Mon Sep 17 00:00:00 2001 From: John Niang Date: Thu, 12 Sep 2024 11:02:21 +0800 Subject: [PATCH] Update attachment permalink only when handler is available (#6641) --- .../reconciler/AttachmentReconciler.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/application/src/main/java/run/halo/app/core/attachment/reconciler/AttachmentReconciler.java b/application/src/main/java/run/halo/app/core/attachment/reconciler/AttachmentReconciler.java index fa5b722ba..cc99fb226 100644 --- a/application/src/main/java/run/halo/app/core/attachment/reconciler/AttachmentReconciler.java +++ b/application/src/main/java/run/halo/app/core/attachment/reconciler/AttachmentReconciler.java @@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j; 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; @@ -28,6 +27,7 @@ import run.halo.app.extension.controller.Controller; 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 @@ -57,18 +57,15 @@ public class AttachmentReconciler implements Reconciler { 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)) {