Browse Source

Pull request #702: 11.0.24-0102版本插件改动合并

Merge in PG/plugin-repository-s3 from release/11.0 to persist/11.0

* commit '5557571834245356c16b647111a7ff78ed8acc6a':
  REPORT-110235 fix: 漏提交代码
  REPORT-110235 fix: 新增是否保留Metadata的配置
persist/11.0
Lipei-李培 1 year ago
parent
commit
c557fa2045
  1. 4
      plugin.xml
  2. 15
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  3. 21
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

4
plugin.xml

@ -5,13 +5,13 @@
<main-package>com.fanruan.fs</main-package>
<active>yes</active>
<hidden>no</hidden>
<version>1.4.1</version>
<version>1.4.2</version>
<env-version>11.0~11.0</env-version>
<jartime>2023-03-14</jartime>
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[
[2023-11-21]小文件不使用分片上传。 <br/>
[2023-11-21]小文件不使用分片上传, 新增preserveMetadata后台配置<br/>
[2023-08-08]分片上传逻辑优化,模板保存问题修复。 <br/>
[2023-07-24]支持大文件分片上传。 <br/>
[2023-06-30]修复默认配置获取错误的问题,过滤有问题的路径。 <br/>

15
src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java

@ -41,6 +41,9 @@ public class S3Config extends CommonRepoConfig {
@Identifier("maxConnections")
private Conf<Integer> maxConnections = HolderKit.simple(200);
@Identifier("preserveMetadata")
private Conf<Boolean> preserveMetadata = HolderKit.simple(true);
@GetConfig("endPoint")
public String getEndPoint() {
return endPoint.get();
@ -111,6 +114,16 @@ public class S3Config extends CommonRepoConfig {
this.maxConnections.set(maxConnections);
}
@GetConfig("preserveMetadata")
public boolean isPreserveMetadata() {
return preserveMetadata.get();
}
@SetConfig("preserveMetadata")
public void setPreserveMetadata(boolean preserveMetadata) {
this.preserveMetadata.set(preserveMetadata);
}
@Override
public void update(String key) {
super.update(key);
@ -123,6 +136,7 @@ public class S3Config extends CommonRepoConfig {
this.setEnablePathStyleAccess(newConfig.isEnablePathStyleAccess());
this.setSignerOverride(newConfig.getSignerOverride());
this.setMaxConnections(newConfig.getMaxConnections());
this.setPreserveMetadata(newConfig.isPreserveMetadata());
}
}
@ -136,6 +150,7 @@ public class S3Config extends CommonRepoConfig {
cloned.enablePathStyleAccess = (Conf<Boolean>) enablePathStyleAccess.clone();
cloned.signerOverride = (Conf<String>) signerOverride.clone();
cloned.maxConnections = (Conf<Integer>) maxConnections.clone();
cloned.preserveMetadata = (Conf<Boolean>) preserveMetadata.clone();
return cloned;
}
}

21
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -57,6 +57,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
public static final String HTTP = "http:";
private final boolean preserveMetadata;
private final AmazonS3 s3;
private final String bucket;
@ -83,6 +85,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
this.s3 = amazonS3ClientBuilder.build();
this.bucket = config.getBucket();
this.preserveMetadata = config.isPreserveMetadata();
}
@Override
@ -158,19 +161,21 @@ public class S3ResourceRepository extends BaseResourceRepository {
if (length > MULTIPART_UPLOAD_LIMIT) {
multipartUpload(path, new ByteArrayInputStream(data));
} else {
ObjectMetadata metadata;
try {
metadata = s3.getObjectMetadata(bucket, path);
} catch (Exception e) {
ObjectMetadata metadata = null;
if (preserveMetadata) {
try {
metadata = s3.getObjectMetadata(bucket, path);
} catch (Exception ignore) {
}
}
if (metadata == null) {
metadata = new ObjectMetadata();
String mimeType = URLConnection.guessContentTypeFromName(path);
if (mimeType != null) {
metadata.setContentType(mimeType);
}
}
if (metadata != null) {
metadata.setContentLength(length);
}
metadata.setContentLength(length);
s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata);
}
}
@ -269,7 +274,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
try {
s3.putObject(req);
} catch (Exception e) {
LogKit.error("[S3] Failed to create parent path {}", path);
LogKit.error("[S3] Failed to create path {}", path);
return false;
}
return true;

Loading…
Cancel
Save