mirror of
https://github.com/halo-dev/plugin-s3.git
synced 2025-10-17 16:08:25 +00:00
Permalink Adaptation Path Style (#38)
Fixes https://github.com/halo-sigs/plugin-s3/issues/37 ```release-note 永久链接根据访问风格进行拼接 ``` 使用Path Style的策略 修改前:  修改后: 
This commit is contained in:
@@ -147,8 +147,8 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
|
|||||||
"Cannot obtain object key from attachment " + attachment.getMetadata().getName()));
|
"Cannot obtain object key from attachment " + attachment.getMetadata().getName()));
|
||||||
}
|
}
|
||||||
var properties = getProperties(configMap);
|
var properties = getProperties(configMap);
|
||||||
var objectName = getObjectName(properties, objectKey);
|
var objectURL = getObjectURL(properties, objectKey);
|
||||||
return Mono.just(URI.create(objectName));
|
return Mono.just(URI.create(objectURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -166,15 +166,7 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) {
|
Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) {
|
||||||
String externalLink;
|
String externalLink = getObjectURL(properties, objectDetail.uploadState.objectKey);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
var metadata = new Metadata();
|
var metadata = new Metadata();
|
||||||
metadata.setName(UUID.randomUUID().toString());
|
metadata.setName(UUID.randomUUID().toString());
|
||||||
@@ -196,9 +188,14 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
|
|||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getObjectName(S3OsProperties properties, String objectKey) {
|
private String getObjectURL(S3OsProperties properties, String objectKey) {
|
||||||
if (StringUtils.isBlank(properties.getDomain())) {
|
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;
|
return properties.getProtocol() + "://" + host + "/" + objectKey;
|
||||||
} else {
|
} else {
|
||||||
return properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;
|
return properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;
|
||||||
|
Reference in New Issue
Block a user