Permalink Adaptation Path Style (#38)

Fixes https://github.com/halo-sigs/plugin-s3/issues/37

```release-note
永久链接根据访问风格进行拼接
```

使用Path Style的策略
修改前:
![image](https://github.com/halo-sigs/plugin-s3/assets/28662535/631b33f8-e534-445b-bf1c-3edbc9a543bc)


修改后:
![image](https://github.com/halo-sigs/plugin-s3/assets/28662535/ca6edbd4-8455-4246-b49b-f12afc3ea020)
This commit is contained in:
longjuan
2023-05-12 11:52:27 -05:00
committed by GitHub
parent 88490bb80f
commit 5a95b4ced1

View File

@@ -147,8 +147,8 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
"Cannot obtain object key from attachment " + attachment.getMetadata().getName()));
}
var properties = getProperties(configMap);
var objectName = getObjectName(properties, objectKey);
return Mono.just(URI.create(objectName));
var objectURL = getObjectURL(properties, objectKey);
return Mono.just(URI.create(objectURL));
}
@Nullable
@@ -166,15 +166,7 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
}
Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) {
String externalLink;
if (StringUtils.isBlank(properties.getDomain())) {
var host = properties.getBucket() + "." + properties.getEndpoint();
externalLink =
properties.getProtocol() + "://" + host + "/" + objectDetail.uploadState.objectKey;
} else {
externalLink = properties.getProtocol() + "://" + properties.getDomain() + "/"
+ objectDetail.uploadState.objectKey;
}
String externalLink = getObjectURL(properties, objectDetail.uploadState.objectKey);
var metadata = new Metadata();
metadata.setName(UUID.randomUUID().toString());
@@ -196,9 +188,14 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return attachment;
}
private String getObjectName(S3OsProperties properties, String objectKey) {
private String getObjectURL(S3OsProperties properties, String objectKey) {
if (StringUtils.isBlank(properties.getDomain())) {
var host = properties.getBucket() + "." + properties.getEndpoint();
String host;
if (properties.getEnablePathStyleAccess()) {
host = properties.getEndpoint() + "/" + properties.getBucket();
} else {
host = properties.getBucket() + "." + properties.getEndpoint();
}
return properties.getProtocol() + "://" + host + "/" + objectKey;
} else {
return properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;