3 Commits

Author SHA1 Message Date
John Niang
a2120c3a42 Fix the problem of stopping local attachment deletion 2025-07-04 12:00:08 +08:00
John Niang
42e27da86b Ignore non-existing object when deleting (#193) 2025-06-11 00:24:19 +08:00
John Niang
19469d0537 Upgrade Halo Gradle plugin to 0.6.0 (#192) 2025-06-11 00:20:41 +08:00
3 changed files with 16 additions and 22 deletions

View File

@@ -1,17 +1,8 @@
// TODO Remove the buildscript block when the halo devtools plugin is updated to use ASM 9.5 or later.
buildscript {
dependencies {
// force the version of ASM used by the halo devtools plugin
classpath('org.ow2.asm:asm:9.8')
classpath('org.ow2.asm:asm-commons:9.8')
}
}
plugins {
id 'java'
id "com.github.node-gradle.node" version "7.1.0"
id "io.freefair.lombok" version "8.13.1"
id "run.halo.plugin.devtools" version "0.5.0"
id "run.halo.plugin.devtools" version "0.6.0"
id 'org.openapi.generator' version '7.12.0'
}

View File

@@ -1,6 +1,5 @@
pluginManagement {
repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/spring-plugin' }
@@ -9,4 +8,3 @@ pluginManagement {
}
}
rootProject.name = 'plugin-s3'

View File

@@ -77,36 +77,41 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
@Override
public Mono<Attachment> delete(DeleteContext deleteContext) {
return Mono.just(deleteContext).filter(context -> this.shouldHandle(context.policy()))
return Mono.just(deleteContext)
.filter(context -> this.shouldHandle(context.policy()))
.flatMap(context -> {
var objectKey = getObjectKey(context.attachment());
if (objectKey == null) {
log.warn(
"Cannot obtain object key from attachment {}, skip deleting object from S3.",
context.attachment().getMetadata().getName());
return Mono.just(context);
return Mono.just(context.attachment());
} else if (MetadataUtil.nullSafeAnnotations(context.attachment())
.containsKey(SKIP_REMOTE_DELETION_ANNO)) {
log.info("Skip deleting object {} from S3.", objectKey);
return Mono.just(context);
return Mono.just(context.attachment());
}
var properties = S3OsProperties.convertFrom(deleteContext.configMap());
return Mono.using(() -> buildS3Client(properties),
return Mono.using(
() -> buildS3Client(properties),
client -> Mono.fromCallable(
() -> client.deleteObject(DeleteObjectRequest.builder()
.bucket(properties.getBucket())
.key(objectKey)
.build())).subscribeOn(Schedulers.boundedElastic()),
S3Client::close)
.build())),
S3Client::close
)
.subscribeOn(Schedulers.boundedElastic())
.doOnNext(response -> {
checkResult(response, "delete object");
log.info("Delete object {} from bucket {} successfully",
objectKey, properties.getBucket());
})
.thenReturn(context);
})
.onErrorMap(S3ExceptionHandler::map)
.map(DeleteContext::attachment);
// ignore when the object does not exist
.onErrorComplete(NoSuchKeyException.class::isInstance)
.onErrorMap(S3ExceptionHandler::map)
.thenReturn(context.attachment());
});
}
@Override