diff --git a/.gitignore b/.gitignore index fda0af54e..eadd96ccc 100755 --- a/.gitignore +++ b/.gitignore @@ -71,4 +71,5 @@ application-local.yaml application-local.properties ### Zip file for test -!src/test/resources/themes/*.zip \ No newline at end of file +!src/test/resources/themes/*.zip +src/main/resources/console/ diff --git a/src/main/java/run/halo/app/core/extension/reconciler/attachment/AttachmentReconciler.java b/src/main/java/run/halo/app/core/extension/reconciler/attachment/AttachmentReconciler.java index 3d7d9a609..6ec9d211f 100644 --- a/src/main/java/run/halo/app/core/extension/reconciler/attachment/AttachmentReconciler.java +++ b/src/main/java/run/halo/app/core/extension/reconciler/attachment/AttachmentReconciler.java @@ -1,9 +1,13 @@ package run.halo.app.core.extension.reconciler.attachment; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.HashSet; +import java.util.Objects; import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.pf4j.PluginManager; +import org.springframework.web.util.UriUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import run.halo.app.core.extension.attachment.Attachment; @@ -63,10 +67,8 @@ public class AttachmentReconciler implements Reconciler { var localRelativePath = annotations.get(Constant.LOCAL_REL_PATH_ANNO_KEY); if (localRelativePath != null) { // TODO Add router function here. - permalink = externalUrl.get() - .resolve("/upload/" + localRelativePath) - .normalize() - .toASCIIString(); + var encodedPath = UriUtils.encodePath("/upload/" + localRelativePath, UTF_8); + permalink = externalUrl.get().resolve(encodedPath).normalize().toString(); } else { var externalLink = annotations.get(Constant.EXTERNAL_LINK_ANNO_KEY); if (externalLink != null) { @@ -79,19 +81,25 @@ public class AttachmentReconciler implements Reconciler { var status = attachment.getStatus(); if (status == null) { status = new AttachmentStatus(); + attachment.setStatus(status); } status.setPermalink(permalink); - - // update status - attachment.setStatus(status); - client.update(attachment); } } + updateStatus(request.name(), attachment.getStatus()); }); - return null; } + void updateStatus(String attachmentName, AttachmentStatus status) { + client.fetch(Attachment.class, attachmentName) + .filter(attachment -> !Objects.deepEquals(attachment.getStatus(), status)) + .ifPresent(attachment -> { + attachment.setStatus(status); + client.update(attachment); + }); + } + void removeFinalizer(String attachmentName) { client.fetch(Attachment.class, attachmentName).ifPresent(attachment -> { var finalizers = attachment.getMetadata().getFinalizers(); diff --git a/src/test/java/run/halo/app/core/extension/endpoint/AttachmentEndpointTest.java b/src/test/java/run/halo/app/core/extension/endpoint/AttachmentEndpointTest.java deleted file mode 100644 index 7b3c4997e..000000000 --- a/src/test/java/run/halo/app/core/extension/endpoint/AttachmentEndpointTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package run.halo.app.core.extension.endpoint; - -class AttachmentEndpointTest { - -} \ No newline at end of file