Compare commits

..

10 Commits

Author SHA1 Message Date
Seth.Tian 638f5cab3f Pull request #19: QFX-5192 回退,改为修改metadata的length 4 years ago
Seth.Tian 6ca4a6a943 Merge remote-tracking branch 'origin/master' 4 years ago
Seth.Tian 7317ba5d24 QFX-5192 update:写入的方法回退,改为修改metadata的length 4 years ago
Seth.Tian 5793a02da6 Pull request #18: QFX-5192 update:更新版本号,修复一个key存在但是length不一样时会导致写入文件不对的问题 4 years ago
Seth.Tian 42110ac049 QFX-5192 update:更新版本号,修复一个key存在但是length不一样时会导致写入失败的问题 4 years ago
richie ff1ca0bc3c 应该在父依赖下申明 4 years ago
ju|剧浩宇 07283b3bf3 Pull request #13: 无jira任务 更新依赖以及版本号 4 years ago
Seth.Tian b471687529 无jira任务 update:更新依赖以及版本号 4 years ago
Echen 5a5ffed822 Pull request #7: QFX-3714 S3插件 copy重写 4 years ago
Seth.Tian 2d967fa5fe QFX-3714 update:重写s3的copy方法 4 years ago
  1. 6
      build.gradle
  2. 123
      build.xml
  3. BIN
      lib/httpclient-4.5.9.jar
  4. BIN
      lib/jackson-annotations-2.13.3.jar
  5. BIN
      lib/jackson-annotations-2.6.0.jar
  6. BIN
      lib/jackson-core-2.13.3.jar
  7. BIN
      lib/jackson-core-2.6.7.jar
  8. BIN
      lib/jackson-databind-2.13.3.jar
  9. BIN
      lib/jackson-databind-2.6.7.3.jar
  10. BIN
      lib/jackson-dataformat-cbor-2.13.3.jar
  11. BIN
      lib/jackson-dataformat-cbor-2.6.7.jar
  12. 22
      plugin.xml
  13. 4
      src/main/java/com/fanruan/fs/s3/repository/S3FileServerResource.java
  14. 70
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  15. 42
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  16. 2
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java
  17. 399
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java
  18. 6
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3.properties
  19. 12
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_en_US.properties
  20. 10
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_ja_JP.properties
  21. 10
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_ko_KR.properties
  22. 11
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_CN.properties
  23. 10
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_TW.properties
  24. 173
      src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js

6
build.gradle

@ -1,4 +1,3 @@
apply plugin: 'java' apply plugin: 'java'
@ -10,8 +9,6 @@ ext {
*/ */
libPath = "$projectDir/../webroot/WEB-INF/lib" libPath = "$projectDir/../webroot/WEB-INF/lib"
fineVersion = '11.0-jsy-20221012'
/** /**
* class进行加密保护 * class进行加密保护
*/ */
@ -120,8 +117,5 @@ dependencies {
//使jar //使jar
implementation fileTree(dir: 'lib', include: ['**/*.jar']) implementation fileTree(dir: 'lib', include: ['**/*.jar'])
implementation fileTree(dir: libPath, include: ['**/*.jar']) implementation fileTree(dir: libPath, include: ['**/*.jar'])
compileOnly('com.fanruan.hihidata:fine-core:' + fineVersion)
compileOnly('com.fanruan.hihidata:fine-cbb:' + fineVersion)
compileOnly('com.fanruan.hihidata:fine-decision:' + fineVersion)
} }

123
build.xml

@ -1,123 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin-repository-s3">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>
<property name="current-version" value="${plugin.version}"/>
<!-- 插件版本-->
<property name="plugin-version" value="${current-version}"/>
<!-- 插件名字-->
<property name="plugin-name" value="s3-repository"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
<delete dir="${classes}"/>
<delete dir="fr-plugin-${plugin-name}-${plugin-version}"/>
<xmlproperty file="${basedir}/plugin.xml"/>
<delete dir="${destLoc}/${plugin.name}"/>
</target>
<path id="compile.classpath">
<fileset dir="${libs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${publicLibs}">
<include name="**/*.jar"/>
</fileset>
</path>
<patternset id="resources4Jar">
<exclude name="**/.settings/**"/>
<exclude name=".classpath"/>
<exclude name=".project"/>
<exclude name="**/*.java"/>
<exclude name="**/*.db"/>
<exclude name="**/*.g"/>
<exclude name="**/package.html"/>
</patternset>
<target name="copy_resources">
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/>
<delete dir="tmp"/>
<copy todir="tmp">
<fileset dir="${resources_from}/src/main/resources">
<patternset refid="resources4Jar"/>
</fileset>
</copy>
<copy todir="${classes}">
<fileset dir="tmp"/>
</copy>
<delete dir="tmp"/>
</target>
<target name="compile_javas">
<echo message="编译${compile_files}下的Java文件"/>
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}"
target="${target_jdk_version}"
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}"
executable="${compile_jdk_version}/bin/javac">
<src path="${basedir}/src/main/java"/>
<exclude name="**/.svn/**"/>
<compilerarg line="-encoding UTF8 "/>
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="jar_classes">
<echo message="打Jar包:${jar_name}"/>
<delete file="${basedir}/${jar_name}"/>
<jar jarfile="${basedir}/${jar_name}">
<fileset dir="${classes}">
</fileset>
</jar>
</target>
<target name="super_jar" depends="prepare">
<antcall target="copy_resources">
<param name="resources_from" value="${basedir}"/>
</antcall>
<antcall target="compile_javas">
<param name="source_jdk_version" value="1.8"/>
<param name="target_jdk_version" value="1.8"/>
<param name="compile_jdk_version" value="${jdk.home}"/>
<param name="compile_files" value="${basedir}/src"/>
</antcall>
<echo message="compile plugin success!"/>
<antcall target="jar_classes">
<param name="jar_name" value="${plugin-jar}"/>
</antcall>
<delete dir="${classes}"/>
</target>
<target name="jar" depends="super_jar">
<antcall target="zip"/>
</target>
<target name="zip">
<property name="plugin-folder" value="fr-plugin-${plugin-name}-${plugin-version}"/>
<echo message="----------zip files----------"/>
<mkdir dir="${plugin-folder}"/>
<copy todir="${plugin-folder}">
<fileset dir=".">
<include name="${plugin-jar}"/>
<include name="plugin.xml"/>
</fileset>
<fileset dir="${libs}">
<include name="*.jar"/>
<include name="*.dll"/>
</fileset>
</copy>
<zip destfile="${basedir}/${plugin-folder}.zip" basedir=".">
<include name="${plugin-folder}/*.jar"/>
<include name="${plugin-folder}/*.dll"/>
<include name="${plugin-folder}/plugin.xml"/>
</zip>
<xmlproperty file="${basedir}/plugin.xml"/>
<move file="${plugin-folder}.zip" todir="${destLoc}/${plugin.name}"/>
<delete dir="${plugin-folder}"/>
</target>
</project>

BIN
lib/httpclient-4.5.13.jar → lib/httpclient-4.5.9.jar

Binary file not shown.

BIN
lib/jackson-annotations-2.13.3.jar

Binary file not shown.

BIN
lib/jackson-annotations-2.6.0.jar

Binary file not shown.

BIN
lib/jackson-core-2.13.3.jar

Binary file not shown.

BIN
lib/jackson-core-2.6.7.jar

Binary file not shown.

BIN
lib/jackson-databind-2.13.3.jar

Binary file not shown.

BIN
lib/jackson-databind-2.6.7.3.jar

Binary file not shown.

BIN
lib/jackson-dataformat-cbor-2.13.3.jar

Binary file not shown.

BIN
lib/jackson-dataformat-cbor-2.6.7.jar

Binary file not shown.

22
plugin.xml

@ -1,29 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin> <plugin>
<id>com.fanruan.fs.s3.repository.v11</id> <id>com.fanruan.fs.s3.repository</id>
<name><![CDATA[S3资源仓库]]></name> <name><![CDATA[S3资源仓库]]></name>
<main-package>com.fanruan.fs</main-package> <main-package>com.fanruan.fs</main-package>
<active>yes</active> <active>yes</active>
<hidden>no</hidden> <hidden>no</hidden>
<version>1.3.8</version> <version>2.2</version>
<env-version>11.0~11.0</env-version> <env-version>10.0</env-version>
<jartime>2021-08-30</jartime> <jartime>2020-01-27</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description> <description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2023-08-07]修改分片上传方法<br/> [2021-01-11]重写copy实现。<br/>
[2022-07-25]修复http无法连接,而https和缺省的时候正常<br/>
[2022-06-30]新增enablePathStyleAccess、signerOverride后台配置<br/>
[2022-06-13]第三方组件升级<br/>
[2022-03-10]第三方组件升级<br/>
[2021-12-29]插件引用的url更改<br/>
[2021-10-08]修复文件夹误判问题。<br/>
[2021-07-16]提供韩文、日文、繁体等国际化文件。 <br/>
[2021-04-23]copyFile接口兼容。 <br/>
[2021-03-30]修复copy文件耗时问题。<br/>
[2021-01-28]修复备份还原S3报警告问题。<br/>
[2021-01-24]修复定时调度结果文件预览失败。<br/>
[2021-01-20]正式作为官方插件维护。<br/>
[2020-12-16]修复远程设计新增、修改模板问题。<br/> [2020-12-16]修复远程设计新增、修改模板问题。<br/>
[2020-10-29]修复连接不释放问题。<br/> [2020-10-29]修复连接不释放问题。<br/>
[2020-08-17]修复key不存在时报错的问题。<br/> [2020-08-17]修复key不存在时报错的问题。<br/>

4
src/main/java/com/fanruan/fs/s3/repository/S3FileServerResource.java

@ -1,7 +1,7 @@
package com.fanruan.fs.s3.repository; package com.fanruan.fs.s3.repository;
import com.fr.decision.fun.impl.AbstractWebResourceProvider; import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.CommonComponent; import com.fr.decision.web.MainComponent;
import com.fanruan.fs.s3.repository.web.S3FileServerComponent; import com.fanruan.fs.s3.repository.web.S3FileServerComponent;
import com.fr.web.struct.Atom; import com.fr.web.struct.Atom;
@ -14,7 +14,7 @@ public class S3FileServerResource extends AbstractWebResourceProvider {
@Override @Override
public Atom attach() { public Atom attach() {
return CommonComponent.KEY; return MainComponent.KEY;
} }
@Override @Override

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

@ -1,8 +1,8 @@
package com.fanruan.fs.s3.repository.core; package com.fanruan.fs.s3.repository.core;
import com.fanruan.api.conf.HolderKit;
import com.fr.config.Identifier; import com.fr.config.Identifier;
import com.fr.config.holder.Conf; import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.io.config.CommonRepoConfig; import com.fr.io.config.CommonRepoConfig;
import com.fr.io.context.ResourceModuleContext; import com.fr.io.context.ResourceModuleContext;
import com.fr.io.context.info.GetConfig; import com.fr.io.context.info.GetConfig;
@ -21,25 +21,19 @@ public class S3Config extends CommonRepoConfig {
} }
@Identifier("endPoint") @Identifier("endPoint")
private Conf<String> endPoint = HolderKit.simple(StringUtils.EMPTY); private Conf<String> endPoint = Holders.simple(StringUtils.EMPTY);
@Identifier("region") @Identifier("region")
private Conf<String> region = HolderKit.simple(StringUtils.EMPTY); private Conf<String> region = Holders.simple(StringUtils.EMPTY);
@Identifier("accessKeyId") @Identifier("accessKeyId")
private Conf<String> accessKeyId = HolderKit.simple(StringUtils.EMPTY); private Conf<String> accessKeyId = Holders.simple(StringUtils.EMPTY);
@Identifier("bucket") @Identifier("accessKeySecret")
private Conf<String> bucket = HolderKit.simple(StringUtils.EMPTY); private Conf<String> accessKeySecret = Holders.simple(StringUtils.EMPTY);
@Identifier("keepAlive")
private Conf<Boolean> keepAlive = HolderKit.simple(false);
@Identifier("useGzip")
private Conf<Boolean> useGzip = HolderKit.simple(false);
@Identifier("maxConnection") @Identifier("bucket")
private Conf<Integer> maxConnection = HolderKit.simple(50); private Conf<String> bucket = Holders.simple(StringUtils.EMPTY);
@GetConfig("endPoint") @GetConfig("endPoint")
public String getEndPoint() { public String getEndPoint() {
@ -71,6 +65,16 @@ public class S3Config extends CommonRepoConfig {
this.accessKeyId.set(accessKeyId); this.accessKeyId.set(accessKeyId);
} }
@GetConfig("accessKeySecret")
public String getAccessKeySecret() {
return accessKeySecret.get();
}
@SetConfig("accessKeySecret")
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret.set(accessKeySecret);
}
@GetConfig("bucket") @GetConfig("bucket")
public String getBucket() { public String getBucket() {
return bucket.get(); return bucket.get();
@ -81,36 +85,6 @@ public class S3Config extends CommonRepoConfig {
this.bucket.set(bucket); this.bucket.set(bucket);
} }
@GetConfig("keepAlive")
public boolean getKeepAlive() {
return this.keepAlive.get();
}
@SetConfig("keepAlive")
public void setKeepAlive(boolean keepAlive) {
this.keepAlive.set(keepAlive);
}
@GetConfig("useGzip")
public boolean getUseGzip() {
return useGzip.get();
}
@SetConfig("useGzip")
public void setUseGzip(boolean useGzip) {
this.useGzip.set(useGzip);
}
@GetConfig("maxConnection")
public int getMaxConnection() {
return maxConnection.get();
}
@SetConfig("maxConnection")
public void setMaxConnection(int maxConnection) {
this.maxConnection.set(maxConnection);
}
@Override @Override
public void update(String key) { public void update(String key) {
super.update(key); super.update(key);
@ -119,10 +93,8 @@ public class S3Config extends CommonRepoConfig {
this.setEndPoint(newConfig.getEndPoint()); this.setEndPoint(newConfig.getEndPoint());
this.setRegion(newConfig.getRegion()); this.setRegion(newConfig.getRegion());
this.setAccessKeyId(newConfig.getAccessKeyId()); this.setAccessKeyId(newConfig.getAccessKeyId());
this.setAccessKeySecret(newConfig.getAccessKeySecret());
this.setBucket(newConfig.getBucket()); this.setBucket(newConfig.getBucket());
this.setKeepAlive(newConfig.getKeepAlive());
this.setUseGzip(newConfig.getUseGzip());
this.setMaxConnection(newConfig.getMaxConnection());
} }
} }
@ -132,10 +104,8 @@ public class S3Config extends CommonRepoConfig {
cloned.endPoint = (Conf<String>) endPoint.clone(); cloned.endPoint = (Conf<String>) endPoint.clone();
cloned.region = (Conf<String>) region.clone(); cloned.region = (Conf<String>) region.clone();
cloned.accessKeyId = (Conf<String>) accessKeyId.clone(); cloned.accessKeyId = (Conf<String>) accessKeyId.clone();
cloned.accessKeySecret = (Conf<String>) accessKeySecret.clone();
cloned.bucket = (Conf<String>) bucket.clone(); cloned.bucket = (Conf<String>) bucket.clone();
cloned.useGzip = (Conf<Boolean>) useGzip.clone();
cloned.keepAlive = (Conf<Boolean>) keepAlive.clone();
cloned.maxConnection = (Conf<Integer>) maxConnection.clone();
return cloned; return cloned;
} }
} }

42
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java

@ -1,17 +1,19 @@
package com.fanruan.fs.s3.repository.core; package com.fanruan.fs.s3.repository.core;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fr.io.base.provider.impl.ConfigRepositoryFactory; import com.fr.io.base.provider.impl.ConfigRepositoryFactory;
import com.fr.io.context.info.RepositoryProfile; import com.fr.io.context.info.RepositoryProfile;
import com.fr.io.repository.ResourceRepository; import com.fr.io.repository.ResourceRepository;
import com.fr.stable.StringUtils; import com.fr.stable.AssistUtils;
import java.io.IOException;
/** /**
* @author richie * @author richie
@ -21,6 +23,8 @@ import com.fr.stable.StringUtils;
public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> { public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
static final String IDENTITY = "S3"; static final String IDENTITY = "S3";
private static final String TEST_KEY = "test_key";
private static final String TEST_CONTENT = "test content";
public S3RepositoryFactory() { public S3RepositoryFactory() {
super(IDENTITY); super(IDENTITY);
@ -39,23 +43,39 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
@Override @Override
public boolean verifyConfig(S3Config config) { public boolean verifyConfig(S3Config config) {
try { try {
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getAccessKeySecret());
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() AmazonS3 s3 = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(credentials)); .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
ClientConfiguration clientConfiguration = new ClientConfiguration(); // listObjects方法存在问题,如果key中包含URL编码的内容,将会抛异常,修改为读写验证是否可用
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); s3.putObject(config.getBucket(), TEST_KEY, TEST_CONTENT);
AmazonS3 s3 = amazonS3ClientBuilder.build(); try (S3Object object = s3.getObject(config.getBucket(), TEST_KEY)) {
s3.listObjects(config.getBucket()); final String content = getContent(object);
s3.deleteObject(config.getBucket(), TEST_KEY);
return AssistUtils.equals(TEST_CONTENT, content);
}
} catch (Exception e) { } catch (Exception e) {
LogKit.error(e.getMessage(), e); LogKit.error(e.getMessage(), e);
return false; return false;
} }
return true;
} }
@Override @Override
public ResourceRepository produce(String repoName, String workRoot, S3Config config) { public ResourceRepository produce(String repoName, String workRoot, S3Config config) {
return new S3ResourceRepository(repoName, workRoot, config); return new S3ResourceRepository(repoName, workRoot, config);
} }
private String getContent(S3Object object) {
final StringBuilder stringBuilder = new StringBuilder();
try (S3ObjectInputStream objectContent = object.getObjectContent()) {
final byte[] bytes = new byte[4096];
int i = 0;
while ((i = objectContent.read(bytes)) > -1) {
stringBuilder.append(new String(bytes, 0, i));
}
} catch (IOException e) {
LogKit.error(e.getMessage(), e);
}
return stringBuilder.toString();
}
} }

2
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java

@ -30,6 +30,8 @@ public class S3RepositoryProfile extends RepositoryProfile<S3Config> {
this.s3Config.set(s3Config); this.s3Config.set(s3Config);
} }
@Override @Override
public RepositoryProfile<S3Config> clone() throws CloneNotSupportedException { public RepositoryProfile<S3Config> clone() throws CloneNotSupportedException {
S3RepositoryProfile cloned = (S3RepositoryProfile) super.clone(); S3RepositoryProfile cloned = (S3RepositoryProfile) super.clone();

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

@ -1,30 +1,28 @@
package com.fanruan.fs.s3.repository.core; package com.fanruan.fs.s3.repository.core;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest; import com.amazonaws.services.s3.model.CopyObjectRequest;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PartETag;
import com.amazonaws.services.s3.model.PutObjectRequest; import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.amazonaws.services.s3.model.UploadPartRequest;
import com.amazonaws.services.s3.model.UploadPartResult;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.common.util.Strings;
import com.fr.io.repository.FineFileEntry; import com.fr.io.repository.FineFileEntry;
import com.fr.io.repository.base.BaseResourceRepository; import com.fr.io.repository.base.BaseResourceRepository;
import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils;
import com.fr.stable.AssistUtils;
import com.fr.stable.Filter; import com.fr.stable.Filter;
import com.fr.stable.StableUtils;
import com.fr.workspace.resource.ResourceIOException; import com.fr.workspace.resource.ResourceIOException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -42,50 +40,41 @@ import java.util.List;
public class S3ResourceRepository extends BaseResourceRepository { public class S3ResourceRepository extends BaseResourceRepository {
private static final String DELIMITER = "/"; private static final String DELIMITER = "/";
/** private static final String CHAR_SET = "UTF-8";
* 1G
*/ private final AmazonS3 s3;
private static final int LENGTH_LIMIT = 1024 * 1024 * 1024;
/**
* 10M一个分片大小
*/
private static final int PART_SIZE = 10 * 1024 * 1024;
private final AmazonS3 readClient;
private final AmazonS3 writeClient;
private final String bucket; private final String bucket;
public S3ResourceRepository(String repoName, String workRoot, S3Config config) { public S3ResourceRepository(String repoName, String workRoot, S3Config config) {
super(repoName, workRoot); super(repoName, workRoot);
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getAccessKeySecret());
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() this.s3 = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(credentials)).disableChunkedEncoding(); .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setUseGzip(config.getUseGzip());
clientConfiguration.setUseTcpKeepAlive(config.getKeepAlive());
clientConfiguration.setMaxConnections(config.getMaxConnection());
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
this.readClient = amazonS3ClientBuilder.build();
this.writeClient = amazonS3ClientBuilder.build();
this.bucket = config.getBucket(); this.bucket = config.getBucket();
} }
@Override @Override
public String getSeparator() { public String getSeparator() {
return DELIMITER; return "/";
} }
@Override @Override
public FineFileEntry getEntry(String path) { public FineFileEntry getEntry(String path) {
GetObjectRequest request = new GetObjectRequest(bucket, path);
try { try {
ObjectMetadata metadata = readClient.getObjectMetadata(bucket, path); S3Object s3Object = s3.getObject(request);
return s3Object2FileEntry(metadata, path); try {
return s3Object2FileEntry(s3Object, path);
} finally {
s3Object.close();
}
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "{} not exist!", path); LogKit.info("{} not exist!", path);
return null;
} }
return null;
} }
@Override @Override
@ -94,27 +83,67 @@ public class S3ResourceRepository extends BaseResourceRepository {
if (!dir.endsWith(DELIMITER)) { if (!dir.endsWith(DELIMITER)) {
dir += DELIMITER; dir += DELIMITER;
} }
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(this.bucket) ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket)
.withPrefix(dir).withDelimiter(DELIMITER); .withPrefix(dir).withDelimiter(DELIMITER);
String nextMarker = null; ObjectListing objectListing = s3.listObjects(listObjectsRequest);
ObjectListing objectListing; for (S3ObjectSummary summary : objectListing.getObjectSummaries()) {
do { String key = summary.getKey();
objectListing = this.readClient.listObjects(listObjectsRequest.withMarker(nextMarker)); if (!key.endsWith(DELIMITER)) {
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { result.add(s3Object2FileEntry(summary, key));
String key = summary.getKey(); }
if (!key.endsWith(DELIMITER)) { }
result.add(s3Object2FileEntry(summary, key)); for (String prefix : objectListing.getCommonPrefixes()) {
FineFileEntry entry = new FineFileEntry(prefix);
entry.setDirectory(true);
result.add(entry);
}
return result.toArray(new FineFileEntry[0]);
}
@Override
public boolean copy(String source, String target) throws ResourceIOException {
if (AssistUtils.equals(source, target)
|| Strings.isEmpty(source)
|| Strings.isEmpty(target)) {
return true;
}
boolean result = true;
if (this.isDirectory(source)) {
final String[] list = list(source);
if (!ArrayUtils.isEmpty(list)) {
for (String s : list) {
String targetKey = StableUtils.pathJoin(target, s);
String sourceKey = StableUtils.pathJoin(source, s);
result = result && this.copy(sourceKey, targetKey);
} }
} }
for (String prefix : objectListing.getCommonPrefixes()) { } else {
FineFileEntry entry = new FineFileEntry(prefix); try {
entry.setDirectory(true); s3.copyObject(bucket, source, bucket, target);
result.add(entry); return true;
} catch (Exception e) {
LogKit.error(e, "copy {} to {} failed, because : ", source, target, e.getMessage());
return false;
} }
}
return result;
}
nextMarker = objectListing.getNextMarker(); private FineFileEntry s3Object2FileEntry(S3ObjectSummary s3Object, String path) {
} while (objectListing.isTruncated()); FineFileEntry entry = new FineFileEntry(path);
return result.toArray(new FineFileEntry[0]); entry.setDirectory(s3Object.getKey().endsWith("/"));
entry.setSize(s3Object.getSize());
entry.setTimestamp(s3Object.getLastModified().getTime());
return entry;
}
private FineFileEntry s3Object2FileEntry(S3Object s3Object, String path) {
FineFileEntry entry = new FineFileEntry(path);
entry.setDirectory(s3Object.getKey().endsWith("/"));
entry.setSize(s3Object.getObjectMetadata().getContentLength());
entry.setTimestamp(s3Object.getObjectMetadata().getLastModified().getTime());
return entry;
} }
@Override @Override
@ -126,9 +155,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
public InputStream read(String filePath) throws ResourceIOException { public InputStream read(String filePath) throws ResourceIOException {
GetObjectRequest request = new GetObjectRequest(bucket, filePath); GetObjectRequest request = new GetObjectRequest(bucket, filePath);
try { try {
return readClient.getObject(request).getObjectContent(); return s3.getObject(request).getObjectContent();
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().warn(e, "[S3] read path {} is error!", filePath);
return new ByteArrayInputStream(new byte[0]); return new ByteArrayInputStream(new byte[0]);
} }
} }
@ -137,144 +165,60 @@ public class S3ResourceRepository extends BaseResourceRepository {
public void write(String path, byte[] data) { public void write(String path, byte[] data) {
ObjectMetadata metadata; ObjectMetadata metadata;
try { try {
metadata = this.readClient.getObjectMetadata(this.bucket, path); metadata = s3.getObjectMetadata(bucket, path);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().warn("[S3] getObjectMetaData error ,path {}", path);
metadata = new ObjectMetadata(); metadata = new ObjectMetadata();
String mimeType = URLConnection.guessContentTypeFromName(path); String mimeType = URLConnection.guessContentTypeFromName(path);
if (mimeType != null) { if (mimeType != null) {
metadata.setContentType(mimeType); metadata.setContentType(mimeType);
} }
metadata.setContentLength(data.length);
} }
if (metadata != null) { if (metadata != null) {
metadata.setContentLength(data.length); metadata.setContentLength(data.length);
} }
writeClient.putObject(bucket, path, new ByteArrayInputStream(data), metadata); s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata);
}
@Override
public void write(String path, InputStream inputStream) throws ResourceIOException {
if (null == inputStream) {
this.writeClient.putObject(this.bucket, path, "");
} else {
ObjectMetadata metadata = new ObjectMetadata();
try {
// 大于1.5G的,就自己算一下长度
if (inputStream.available() > LENGTH_LIMIT) {
List<PartETag> partETags = new ArrayList<>();
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucket, path);
InitiateMultipartUploadResult initResponse = this.writeClient.initiateMultipartUpload(initRequest);
final String uploadId = initResponse.getUploadId();
byte[] buffer = new byte[PART_SIZE];
int bytesRead;
int partNumber = 1;
while ((bytesRead = inputStream.read(buffer)) > 0) {
// Create the request to upload a part.
UploadPartRequest uploadRequest = new UploadPartRequest()
.withBucketName(bucket)
.withKey(path)
.withUploadId(uploadId)
.withPartNumber(partNumber)
.withInputStream(new ByteArrayInputStream(buffer, 0, bytesRead))
.withPartSize(bytesRead);
final UploadPartResult uploadPartResult = this.writeClient.uploadPart(uploadRequest);
partETags.add(uploadPartResult.getPartETag());
partNumber++;
}
CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucket, path,
initResponse.getUploadId(), partETags);
this.writeClient.completeMultipartUpload(compRequest);
} else {
metadata.setContentLength(inputStream.available());
this.writeClient.putObject(this.bucket, path, inputStream, metadata);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().info("S3 inputStream.putObject error,path is {}, error message {}", path, e.getMessage());
} finally {
try {
inputStream.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] error,path is {}, error message {}", path, e.getMessage());
}
}
}
} }
@Override @Override
public boolean createFile(String path) { public boolean createFile(String path) {
List<String> paths = getAllNecessaryPath(path); PutObjectRequest request = new PutObjectRequest(bucket, path, new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
for (int i = paths.size() - 1; i >= 0; i--) { try {
String parent = paths.get(i); s3.putObject(request);
PutObjectRequest req = new PutObjectRequest(this.bucket, parent, new ByteArrayInputStream(new byte[0]), buildEmptyMetadata()); } catch (Exception e) {
try { return false;
this.writeClient.putObject(req);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] Failed to create parent path {}", parent);
return false;
}
} }
return true; return true;
} }
@Override @Override
public boolean createDirectory(String path) { public boolean createDirectory(String path) {
if (!path.endsWith(DELIMITER)) { PutObjectRequest request = new PutObjectRequest(bucket, path + "/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
path += DELIMITER; try {
} s3.putObject(request);
List<String> paths = getAllNecessaryPath(path); } catch (Exception e) {
for (int i = paths.size() - 1; i >= 0; i--) { return false;
String parent = paths.get(i);
PutObjectRequest req = new PutObjectRequest(bucket, parent, new ByteArrayInputStream(new byte[0]), buildEmptyMetadata());
try {
writeClient.putObject(req);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] Failed to create parent path {}", parent);
return false;
}
} }
return true; return true;
} }
@Override @Override
public boolean delete(String path) { public boolean delete(String path) {
this.writeClient.deleteObject(this.bucket, path);
String prefix = path;
if (!path.endsWith(DELIMITER)) {
prefix = path + DELIMITER;
}
try { try {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(this.bucket) s3.deleteObject(bucket, path);
.withPrefix(prefix).withDelimiter(DELIMITER);
ObjectListing objectListing;
String nextMarker = null;
do {
objectListing = this.readClient.listObjects(listObjectsRequest.withMarker(nextMarker));
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) {
String key = summary.getKey();
if (!key.endsWith(DELIMITER)) {
this.writeClient.deleteObject(this.bucket, key);
}
}
for (String pre : objectListing.getCommonPrefixes()) {
delete(pre);
}
nextMarker = objectListing.getNextMarker();
} while (objectListing.isTruncated());
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] delete error path {}", path); LogKit.error(e.getMessage(), e);
return false;
} }
this.writeClient.deleteObject(this.bucket, prefix);
return true; return true;
} }
@Override @Override
public boolean exist(String path) { public boolean exist(String path) {
try { try {
return this.readClient.doesObjectExist(this.bucket, path) || this.readClient.doesObjectExist(this.bucket, path + DELIMITER); return s3.doesObjectExist(bucket, path);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] exist error path {}", path);
return false; return false;
} }
} }
@ -285,52 +229,55 @@ public class S3ResourceRepository extends BaseResourceRepository {
if (!dir.endsWith(DELIMITER)) { if (!dir.endsWith(DELIMITER)) {
dir += DELIMITER; dir += DELIMITER;
} }
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(this.bucket) ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket)
.withPrefix(dir).withDelimiter(DELIMITER); .withPrefix(dir).withDelimiter(DELIMITER);
String nextMarker = null; ObjectListing objectListing = s3.listObjects(listObjectsRequest);
ObjectListing objectListing; for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
do { String[] arr = objectSummary.getKey().split(DELIMITER);
objectListing = this.readClient.listObjects(listObjectsRequest.withMarker(nextMarker)); String name = arr[arr.length - 1];
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { if (filter == null) {
String key = objectSummary.getKey(); result.add(name);
if (StringKit.equals(key, dir)) { } else {
continue; if (filter.accept(name)) {
}
String[] arr = key.split(DELIMITER);
String name = arr[arr.length - 1];
if (filter == null) {
result.add(name); result.add(name);
} else {
if (filter.accept(name)) {
result.add(name);
}
} }
} }
for (String prefix : objectListing.getCommonPrefixes()) { }
String[] arr = prefix.split(DELIMITER); for (String prefix : objectListing.getCommonPrefixes()) {
String name = arr[arr.length - 1] + DELIMITER; String[] arr = prefix.split(DELIMITER);
if (filter == null) { String name = arr[arr.length - 1] + DELIMITER;
if (filter == null) {
result.add(name);
} else {
if (filter.accept(name)) {
result.add(name); result.add(name);
} else {
if (filter.accept(name)) {
result.add(name);
}
} }
} }
nextMarker = objectListing.getNextMarker(); }
} while (objectListing.isTruncated());
return result.toArray(new String[0]); return result.toArray(new String[0]);
} }
@Override @Override
public boolean isDirectory(String path) { public boolean isDirectory(String path) {
return exist(path.endsWith(DELIMITER) ? path : path + DELIMITER); if (path.endsWith(DELIMITER)) {
return true;
}
ObjectListing listing = s3.listObjects(bucket, path);
if (listing.getObjectSummaries().isEmpty()) {
return false;
}
if (listing.getObjectSummaries().size() > 1) {
return true;
} else {
S3ObjectSummary summary = listing.getObjectSummaries().get(0);
return !StringKit.equals(listing.getPrefix(), summary.getKey());
}
} }
@Override @Override
public long lastModified(String path) { public long lastModified(String path) {
try { try {
S3Object s3Object = this.readClient.getObject(this.bucket, path); S3Object s3Object = s3.getObject(bucket, path);
if (s3Object != null) { if (s3Object != null) {
try { try {
return s3Object.getObjectMetadata().getLastModified().getTime(); return s3Object.getObjectMetadata().getLastModified().getTime();
@ -339,18 +286,25 @@ public class S3ResourceRepository extends BaseResourceRepository {
} }
} }
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[S3] {} not exist!", path); LogKit.info("{} not exist!", path);
} }
return -1L; return -1L;
} }
@Override @Override
public long length(String path) { public long length(String path) {
try { try {
ObjectMetadata metadata = this.readClient.getObjectMetadata(this.bucket, path); S3Object s3Object = s3.getObject(bucket, path);
return metadata.getContentLength(); if (s3Object != null) {
try {
return s3Object.getObjectMetadata().getContentLength();
} finally {
s3Object.close();
}
}
} catch (Exception e) { } catch (Exception e) {
LogKit.info("[S3] {} not exist!", path); LogKit.info("{} not exist!", path);
} }
return -1L; return -1L;
@ -358,27 +312,21 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public boolean rename(String path, String newPath) throws ResourceIOException { public boolean rename(String path, String newPath) throws ResourceIOException {
if (copy(path, newPath) && delete(path)) { try {
if (FineLoggerFactory.getLogger().isDebugEnabled()) { CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucket,
FineLoggerFactory.getLogger().debug("[S3] rename {} to {} success.", path, newPath); path, bucket, newPath);
} s3.copyObject(copyObjRequest);
return true; s3.deleteObject(new DeleteObjectRequest(bucket, path));
} else { } catch (Exception e) {
FineLoggerFactory.getLogger().error("[S3] rename {} to {} failed.", path, newPath); LogKit.error(e.getMessage(), e);
return false; return false;
} }
} return true;
@Override
public boolean copyFile(String origPath, String desPath) throws ResourceIOException {
writeClient.copyObject(bucket, origPath, bucket, desPath);
return exist(desPath);
} }
@Override @Override
public void shutDown() { public void shutDown() {
readClient.shutdown(); s3.shutdown();
writeClient.shutdown();
} }
@Override @Override
@ -386,53 +334,4 @@ public class S3ResourceRepository extends BaseResourceRepository {
return S3RepositoryFactory.IDENTITY; return S3RepositoryFactory.IDENTITY;
} }
/*--------------------------------------私有方法-----------------------------------------**/
private ObjectMetadata buildEmptyMetadata() {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(0);
return metadata;
}
private FineFileEntry s3Object2FileEntry(S3ObjectSummary s3Object, String path) {
FineFileEntry entry = new FineFileEntry(path);
entry.setDirectory(s3Object.getKey().endsWith(DELIMITER));
entry.setSize(s3Object.getSize());
entry.setTimestamp(s3Object.getLastModified().getTime());
return entry;
}
private FineFileEntry s3Object2FileEntry(ObjectMetadata metadata, String path) {
FineFileEntry entry = new FineFileEntry(path);
entry.setDirectory(path.endsWith(DELIMITER));
entry.setSize(metadata.getContentLength());
entry.setTimestamp(metadata.getLastModified().getTime());
return entry;
}
/**
* 递归创建父目录的metadata. 比如path是 {@code WEB-INF/reportlets/test/1.cpt}
* 则返回 {@code [WEB-INF/reportlets/test/1.cpt, WEB-INF/reportlets/test/, WEB-INF/reportlets/, WEB-INF/]}
*/
private List<String> getAllNecessaryPath(String path) {
// 获取所有path路径及其所有父路径
List<String> allPath = new ArrayList<>();
allPath.add(path);
int lastIdxOfDelimiter = path.lastIndexOf(DELIMITER);
// 以/结尾的先把末尾的/去掉
if (lastIdxOfDelimiter == path.length() - 1) {
path = path.substring(0, lastIdxOfDelimiter);
lastIdxOfDelimiter = path.lastIndexOf(DELIMITER);
}
while (lastIdxOfDelimiter > 0) {
allPath.add(path.substring(0, lastIdxOfDelimiter + 1));
path = path.substring(0, lastIdxOfDelimiter);
lastIdxOfDelimiter = path.lastIndexOf(DELIMITER);
}
return allPath;
}
} }

6
src/main/resources/com/fanruan/fs/s3/repository/locale/s3.properties

@ -3,8 +3,4 @@ Plugin-S3_End_Point=Endpoint
Plugin-S3_Region=Region Plugin-S3_Region=Region
Plugin-S3_Access_Key_Id=AccessKeyId Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket Plugin-S3_Bucket=Bucket
Dec-Error_Start_With_Slash_Or_End_Without_Slash=The path cannot start with "/", but must end with "/"
Plugin-S3_Keep_Alive=keepAlive
Plugin-S3_Use_Gzip=useGzip
Plugin-S3_Max_Connection=maxConnection

12
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_en_US.properties

@ -1,10 +1,6 @@
Dec-Error_Start_With_Slash_Or_End_Without_Slash=The path cannot start with "/", but must end with "/" Plugin-S3_Input=Please Input
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket
Plugin-S3_End_Point=Endpoint Plugin-S3_End_Point=Endpoint
Plugin-S3_Input=Please input
Plugin-S3_Region=Region Plugin-S3_Region=Region
Plugin-S3_Keep_Alive=keepAlive Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Use_Gzip=useGzip Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Max_Connection=maxConnection Plugin-S3_Bucket=Bucket

10
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_ja_JP.properties

@ -1,10 +0,0 @@
Dec-Error_Start_With_Slash_Or_End_Without_Slash=\u30D1\u30B9\u306F\u300C/\u300D\u3067\u59CB\u307E\u308B\u3053\u3068\u304C\u3067\u304D\u306A\u3044\u3002\u300C/\u300D\u3067\u7D42\u308F\u308B\u5FC5\u8981\u304C\u3042\u308B\u3002
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket
Plugin-S3_End_Point=Endpoint
Plugin-S3_Input=\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u3002
Plugin-S3_Region=Region
Plugin-S3_Keep_Alive=keepAlive
Plugin-S3_Use_Gzip=useGzip
Plugin-S3_Max_Connection=maxConnection

10
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_ko_KR.properties

@ -1,10 +0,0 @@
Dec-Error_Start_With_Slash_Or_End_Without_Slash=
Plugin-S3_Access_Key_Id=
Plugin-S3_Access_Key_Secret=
Plugin-S3_Bucket=
Plugin-S3_End_Point=
Plugin-S3_Input=
Plugin-S3_Region=
Plugin-S3_Keep_Alive=keepAlive
Plugin-S3_Use_Gzip=useGzip
Plugin-S3_Max_Connection=maxConnection

11
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_CN.properties

@ -1,9 +1,6 @@
Dec-Error_Start_With_Slash_Or_End_Without_Slash=\u8DEF\u5F84\u5F00\u5934\u4E0D\u80FD\u52A0\u659C\u6760\uFF0C\u5FC5\u987B\u4EE5\u659C\u6760\u7ED3\u5C3E Plugin-S3_Input=\u8BF7\u8F93\u5165
Plugin-S3_End_Point=Endpoint
Plugin-S3_Region=Region
Plugin-S3_Access_Key_Id=AccessKeyId Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket Plugin-S3_Bucket=Bucket
Plugin-S3_End_Point=Endpoint
Plugin-S3_Input=\u8BF7\u8F93\u5165
Plugin-S3_Keep_Alive=keepAlive
Plugin-S3_Use_Gzip=useGzip
Plugin-S3_Max_Connection=maxConnection

10
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_TW.properties

@ -1,10 +0,0 @@
Dec-Error_Start_With_Slash_Or_End_Without_Slash=\u8DEF\u5F91\u958B\u982D\u4E0D\u80FD\u52A0\u659C\u69D3\uFF0C\u5FC5\u9808\u4EE5\u659C\u69D3\u7D50\u5C3E
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket
Plugin-S3_End_Point=Endpoint
Plugin-S3_Input=\u8ACB\u8F38\u5165
Plugin-S3_Region=Region
Plugin-S3_Keep_Alive=keepAlive
Plugin-S3_Use_Gzip=useGzip
Plugin-S3_Max_Connection=maxConnection

173
src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js

@ -3,26 +3,24 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
value: "S3", // 地址栏显示的hash值 value: "S3", // 地址栏显示的hash值
id: "decision-intelligence-cluster-file-s3", // id id: "decision-intelligence-cluster-file-s3", // id
text: "S3", // 文字 text: "S3", // 文字
cardType: "dec.intelligence.cluster.file.s3", cardType: "dec.intelligence.cluster.file.s3"
workRoot: false,
}); });
return items; return items;
}); });
!(function () { !(function () {
var LABEL_WIDTH = 107, EDITOR_WIDTH = 393; var LABEL_WIDTH = 116, EDITOR_WIDTH = 300;
var S3 = BI.inherit(BI.Widget, { var S3 = BI.inherit(BI.Widget, {
props: { props: {
baseCls: "dec-cluster-ftp", baseCls: "dec-cluster-ftp",
value: {}, value: {}
}, },
_store: function () { _store: function () {
return BI.Models.getModel("dec.model.intelligence.cluster.file.s3", { return BI.Models.getModel("dec.model.intelligence.cluster.file.s3", {
value: this.options.value, value: this.options.value
}); });
}, },
@ -30,7 +28,6 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
return { return {
type: "bi.vertical", type: "bi.vertical",
tgap: 15, tgap: 15,
@ -52,8 +49,8 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action: function () { action: function () {
self.store.setEndPoint(this.getValue()); self.store.setEndPoint(this.getValue());
}, }
}], }]
}, { }, {
type: "dec.label.editor.item", type: "dec.label.editor.item",
textWidth: LABEL_WIDTH, textWidth: LABEL_WIDTH,
@ -71,8 +68,8 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action: function () { action: function () {
self.store.setRegion(this.getValue()); self.store.setRegion(this.getValue());
}, }
}], }]
}, { }, {
type: "dec.label.editor.item", type: "dec.label.editor.item",
textWidth: LABEL_WIDTH, textWidth: LABEL_WIDTH,
@ -90,22 +87,25 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action: function () { action: function () {
self.store.setAccessKeyId(this.getValue()); self.store.setAccessKeyId(this.getValue());
}, }
}], }]
}, },
{ {
type: "dec.common.cipher.editor", type: "dec.label.editor.item",
textWidth: LABEL_WIDTH, textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH, editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Access_Key_Secret"), watermark: BI.i18nText("Plugin-S3_Access_Key_Secret"),
text: BI.i18nText("Plugin-S3_Access_Key_Secret"), text: BI.i18nText("Plugin-S3_Access_Key_Secret"),
value: this.model.password, value: "******",
el: { el: {
disabled: !o.editable disabled: !o.editable,
},
ref: function (_ref) {
self.passwordRow = _ref;
}, },
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setAccessKeySecret(this.getValue());
}
}]
}, },
{ {
type: "dec.label.editor.item", type: "dec.label.editor.item",
@ -115,84 +115,15 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
text: BI.i18nText("Plugin-S3_Bucket"), text: BI.i18nText("Plugin-S3_Bucket"),
value: this.model.bucket, value: this.model.bucket,
el: { el: {
disabled: !o.editable disabled: !o.editable,
}, },
listeners: [{ listeners: [{
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action: function () { action: function () {
self.store.setBucket(this.getValue()); self.store.setBucket(this.getValue());
}, }
}], }]
}, }]
{
type: "dec.label.editor.item",
el: {
disabled: !o.editable,
},
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Dec-Please_Input"),
text: BI.i18nText("Dec-Basic_Path"),
value: this.model.workRoot,
ref: function (_ref) {
self.filePathRow = _ref;
},
},{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Input"),
text: "keepAlive",
value: this.model.keepAlive,
el: {
disabled: !o.editable,
type: "bi.switch",
selected: this.model.keepAlive,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setKeepAlive(this.isSelected());
},
}],
},
},{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Input"),
text: "useGzip",
value: this.model.useGzip,
el: {
disabled: !o.editable,
type: "bi.switch",
selected: this.model.useGzip,
listeners: [
{
eventName: BI.Switcher.EVENT_CHANGE,
action: function () {
self.store.setUseGzip(this.isSelected());
},
},
],
},
},{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Input"),
text: "maxConnection",
value: this.model.maxConnection,
el: {
disabled: !o.editable,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setMaxConnection(this.getValue());
},
}],
},
}],
}; };
}, },
@ -201,37 +132,14 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
endPoint: this.model.endPoint, endPoint: this.model.endPoint,
region: this.model.region, region: this.model.region,
accessKeyId: this.model.accessKeyId, accessKeyId: this.model.accessKeyId,
password: this.passwordRow.getCipher(), accessKeySecret: this.model.accessKeySecret,
bucket: this.model.bucket, bucket: this.model.bucket
keepAlive: this.model.keepAlive,
useGzip: this.model.useGzip,
maxConnection: this.model.maxConnection,
workRoot: this.filePathRow.getValue(),
}; };
}, },
validation: function () {
var valid = true;
var path = this.filePathRow.getValue();
if (Dec.Utils.strLength(path) > DecCst.STRING_SHORT_TEXT_LENGTH) {
this.filePathRow.showError(BI.i18nText("Dec-Error_Length_Greater_Than_Short_Text"));
valid = false;
}
if (BI.startWith(path, "/") || !BI.endWith(path, "/")) {
this.filePathRow.showError(BI.i18nText("Dec-Error_Start_With_Slash_Or_End_Without_Slash"));
valid = false;
}
if (!BI.isKey(path)) {
this.filePathRow.showError(BI.i18nText("Dec-Error_Null"));
valid = false;
}
return valid;
},
}); });
BI.shortcut("dec.intelligence.cluster.file.s3", S3); BI.shortcut("dec.intelligence.cluster.file.s3", S3);
}()); })();
!(function () { !(function () {
@ -239,17 +147,12 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
state: function () { state: function () {
var val = this.options.value; var val = this.options.value;
return { return {
endPoint: val.endPoint, endPoint: val.endPoint,
region: val.region, region: val.region,
accessKeyId: val.accessKeyId, accessKeyId: val.accessKeyId,
password: val.password, accessKeySecret: val.accessKeySecret,
bucket: val.bucket, bucket: val.bucket
workRoot: val.workRoot,
keepAlive: val.keepAlive,
useGzip: val.useGzip,
maxConnection: val.maxConnection||50,
}; };
}, },
@ -257,10 +160,10 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
encodingArray: function () { encodingArray: function () {
return BI.map(DecCst.EncodeConstants.ENCODING_ARRAY, function (i, v) { return BI.map(DecCst.EncodeConstants.ENCODING_ARRAY, function (i, v) {
return { return {
value: v, value: v
}; };
}); });
}, }
}, },
actions: { actions: {
@ -276,19 +179,13 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
this.model.accessKeyId = v; this.model.accessKeyId = v;
}, },
setAccessKeySecret: function (v) {
this.model.accessKeySecret = v;
},
setBucket: function (v) { setBucket: function (v) {
this.model.bucket = v; this.model.bucket = v;
},
setKeepAlive: function (v){
this.model.keepAlive = v;
},
setUseGzip: function (v){
this.model.useGzip = v;
},
setMaxConnection: function (v){
this.model.maxConnection = Number.parseInt(v);
} }
}, }
}); });
BI.model("dec.model.intelligence.cluster.file.s3", Model); BI.model("dec.model.intelligence.cluster.file.s3", Model);
}()); })();
Loading…
Cancel
Save