mirror of
https://github.com/halo-dev/plugin-s3.git
synced 2025-10-16 07:19:45 +00:00

```release-note 友好地提示异常信息 ``` fixes https://github.com/halo-dev/plugin-s3/issues/105 验证方法: 1. ak/sk乱输,发生接收到403状态码(接收错误状态码) 2. endpoint网址改成不存在的,如.com改成.comaaa(未知主机) 3. endpoint端口改成没监听的(超时)
37 lines
1.4 KiB
Java
37 lines
1.4 KiB
Java
package run.halo.s3os;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.server.ServerWebInputException;
|
|
import reactor.core.publisher.Mono;
|
|
import run.halo.app.core.extension.attachment.Attachment;
|
|
import run.halo.app.core.extension.attachment.Policy;
|
|
import run.halo.app.extension.ReactiveExtensionClient;
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class S3UnlinkServiceImpl implements S3UnlinkService {
|
|
private final ReactiveExtensionClient client;
|
|
private final S3OsAttachmentHandler handler;
|
|
|
|
@Override
|
|
public Mono<Attachment> unlink(String name) {
|
|
return client.get(Attachment.class, name)
|
|
.flatMap((attachment) -> client.get(Policy.class, attachment.getSpec().getPolicyName())
|
|
.doOnNext((policy) -> {
|
|
if (!handler.shouldHandle(policy)) {
|
|
throw new ServerWebInputException(
|
|
"This attachment policy is not managed by plugin-s3.");
|
|
}
|
|
}).thenReturn(attachment))
|
|
.flatMap(attachment -> {
|
|
attachment.getMetadata().getAnnotations().put(
|
|
S3OsAttachmentHandler.SKIP_REMOTE_DELETION_ANNO, Boolean.TRUE.toString());
|
|
return client.delete(attachment);
|
|
});
|
|
}
|
|
|
|
}
|