Update attachment permalink only when handler is available (#6641)

pull/6647/head
John Niang 2024-09-12 11:02:21 +08:00 committed by GitHub
parent a36822c861
commit ba18f7010b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 12 deletions

View File

@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.core.attachment.AttachmentUtils; import run.halo.app.core.attachment.AttachmentUtils;
import run.halo.app.core.attachment.ThumbnailService; import run.halo.app.core.attachment.ThumbnailService;
import run.halo.app.core.attachment.ThumbnailSize; 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.ControllerBuilder;
import run.halo.app.extension.controller.Reconciler; import run.halo.app.extension.controller.Reconciler;
import run.halo.app.extension.controller.Reconciler.Request; import run.halo.app.extension.controller.Reconciler.Request;
import run.halo.app.extension.controller.RequeueException;
@Slf4j @Slf4j
@Component @Component
@ -57,18 +57,15 @@ public class AttachmentReconciler implements Reconciler<Request> {
var annotations = attachment.getMetadata().getAnnotations(); var annotations = attachment.getMetadata().getAnnotations();
if (annotations != null) { if (annotations != null) {
attachmentService.getPermalink(attachment) var permalink = attachmentService.getPermalink(attachment)
.map(URI::toASCIIString) .map(URI::toASCIIString)
.switchIfEmpty(Mono.fromSupplier(() -> { .blockOptional()
// Only for back-compatibility .orElseThrow(() -> new RequeueException(new Result(true, null),
return annotations.get(Constant.EXTERNAL_LINK_ANNO_KEY); "Attachment handler is unavailable, requeue the request"
})) ));
.doOnNext(permalink -> { log.debug("Set permalink {} for attachment {}", permalink, request.name());
log.debug("Set permalink {} for attachment {}", permalink, request.name()); var status = nullSafeStatus(attachment);
var status = nullSafeStatus(attachment); status.setPermalink(permalink);
status.setPermalink(permalink);
})
.blockOptional();
} }
var permalink = nullSafeStatus(attachment).getPermalink(); var permalink = nullSafeStatus(attachment).getPermalink();
if (StringUtils.isNotBlank(permalink) && AttachmentUtils.isImage(attachment)) { if (StringUtils.isNotBlank(permalink) && AttachmentUtils.isImage(attachment)) {