From 38b813afefdcbea9f1f43694b34ddf32b9d080d7 Mon Sep 17 00:00:00 2001 From: John Niang Date: Tue, 29 Oct 2024 16:14:12 +0800 Subject: [PATCH] Fix the problem of not being able to delete if storage was deleted (#28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR ignores the error `failed get storage: storage not found; rawPath: ...` while deleting attachments. Fixes #25 /kind bug ```release-note 修复因 AList 存储被删除后无法删除附件的问题 ``` --- .../run/halo/alist/endpoint/AListAttachmentHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/run/halo/alist/endpoint/AListAttachmentHandler.java b/src/main/java/run/halo/alist/endpoint/AListAttachmentHandler.java index 7adb447..03a7877 100644 --- a/src/main/java/run/halo/alist/endpoint/AListAttachmentHandler.java +++ b/src/main/java/run/halo/alist/endpoint/AListAttachmentHandler.java @@ -220,6 +220,14 @@ public Mono delete(DeleteContext deleteContext) { }) .flatMap(result -> { if (!Objects.equals(OK.value(), result.getCode())) { + // According to https://alist.nn.ci/guide/api/fs.html, we have no + // better way to detect whether the storage is not found + if (StringUtils.startsWith( + result.getMessage(), "failed get storage: storage not found" + )) { + // ignore error: storage not found + return Mono.just(attachment); + } return Mono.error(new ServerWebInputException( "Failed to delete file: " + result.getMessage()) );