From c109bbd61f55f761b94cdfc8060814d5bc4c8364 Mon Sep 17 00:00:00 2001 From: John Niang Date: Tue, 1 Aug 2023 18:14:54 +0800 Subject: [PATCH] Fallback to default handler for backward compatibility (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement #### What this PR does / why we need it: See https://github.com/halo-sigs/plugin-s3/issues/56 for more. This PR skips permalink resolution while the object key is missing. So that the default handler will resolve permalink from annotation `storage.halo.run/external-link` #### Which issue(s) this PR fixes: Fixes https://github.com/halo-sigs/plugin-s3/issues/56 #### Does this PR introduce a user-facing change? ```release-note 解决导入 Halo 1.x 附件后出现“Cannot obtain object key from attachment attachment-xyz”的问题 ``` --- src/main/java/run/halo/s3os/S3OsAttachmentHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java index 8317b34..beed0f5 100644 --- a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java +++ b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java @@ -148,8 +148,8 @@ public Mono getPermalink(Attachment attachment, Policy policy, ConfigMap co } var objectKey = getObjectKey(attachment); if (objectKey == null) { - return Mono.error(new IllegalArgumentException( - "Cannot obtain object key from attachment " + attachment.getMetadata().getName())); + // fallback to default handler for backward compatibility + return Mono.empty(); } var properties = getProperties(configMap); var objectURL = getObjectURL(properties, objectKey);