You've already forked FrameTour-BE
Java21
This commit is contained in:
@@ -21,16 +21,12 @@ public class StorageFactory {
|
||||
}
|
||||
|
||||
public static IStorageAdapter get(StorageType storageType) {
|
||||
switch (storageType) {
|
||||
case LOCAL:
|
||||
return new LocalStorageAdapter();
|
||||
case AWS_OSS:
|
||||
return new AwsOssAdapter();
|
||||
case ALI_OSS:
|
||||
return new AliOssAdapter();
|
||||
default:
|
||||
throw new StorageUnsupportedException(storageType.getType());
|
||||
}
|
||||
return switch (storageType) {
|
||||
case LOCAL -> new LocalStorageAdapter();
|
||||
case AWS_OSS -> new AwsOssAdapter();
|
||||
case ALI_OSS -> new AliOssAdapter();
|
||||
default -> throw new StorageUnsupportedException(storageType.getType());
|
||||
};
|
||||
}
|
||||
|
||||
public static IStorageAdapter get(String type) {
|
||||
|
@@ -190,18 +190,13 @@ final public class AliOssAdapter extends AStorageAdapter {
|
||||
}
|
||||
|
||||
private CannedAccessControlList convertAcl(StorageAcl acl) {
|
||||
switch (acl) {
|
||||
case PUBLIC_READ:
|
||||
return CannedAccessControlList.PublicRead;
|
||||
case PUBLIC_READ_WRITE:
|
||||
return CannedAccessControlList.PublicReadWrite;
|
||||
case PRIVATE:
|
||||
return CannedAccessControlList.Private;
|
||||
case AUTHENTICATED_READ:
|
||||
return CannedAccessControlList.AuthenticatedRead;
|
||||
default:
|
||||
return CannedAccessControlList.Default;
|
||||
}
|
||||
return switch (acl) {
|
||||
case PUBLIC_READ -> CannedAccessControlList.PublicRead;
|
||||
case PUBLIC_READ_WRITE -> CannedAccessControlList.PublicReadWrite;
|
||||
case PRIVATE -> CannedAccessControlList.Private;
|
||||
case AUTHENTICATED_READ -> CannedAccessControlList.AuthenticatedRead;
|
||||
default -> CannedAccessControlList.Default;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -61,7 +61,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
}
|
||||
String fullPath = buildPath(path);
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentLength(inputStream.available());
|
||||
if (StringUtils.isNotBlank(contentType)) {
|
||||
@@ -79,7 +79,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
@Override
|
||||
public boolean deleteFile(String... path) {
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
s3Client.deleteObject(config.getBucketName(), buildPath(path));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -95,7 +95,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
@Override
|
||||
public String getUrlForDownload(Date expireDate, String... path) {
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
URL url = s3Client.generatePresignedUrl(config.getBucketName(), buildPath(path), expireDate);
|
||||
return url.toString();
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
@Override
|
||||
public String getUrlForUpload(Date expireDate, String contentType, String... path) {
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(config.getBucketName(), buildPath(path));
|
||||
request.setMethod(HttpMethod.PUT);
|
||||
if (StringUtils.isNotBlank(contentType)) {
|
||||
@@ -126,7 +126,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
String continuationToken = null;
|
||||
List<S3ObjectSummary> objectList = new ArrayList<>();
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
while (isTruncated) {
|
||||
if (continuationToken != null) {
|
||||
listObjectsV2Request.setContinuationToken(continuationToken);
|
||||
@@ -160,7 +160,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
return true;
|
||||
}
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
int idx = 0;
|
||||
int batchSize = 999;
|
||||
while (objectList.size() > idx) {
|
||||
@@ -184,24 +184,19 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
}
|
||||
|
||||
private CannedAccessControlList convertAcl(StorageAcl acl) {
|
||||
switch (acl) {
|
||||
case PUBLIC_READ:
|
||||
return CannedAccessControlList.PublicRead;
|
||||
case PUBLIC_READ_WRITE:
|
||||
return CannedAccessControlList.PublicReadWrite;
|
||||
case PRIVATE:
|
||||
return CannedAccessControlList.Private;
|
||||
case AUTHENTICATED_READ:
|
||||
return CannedAccessControlList.AuthenticatedRead;
|
||||
default:
|
||||
return CannedAccessControlList.PublicRead;
|
||||
}
|
||||
return switch (acl) {
|
||||
case PUBLIC_READ -> CannedAccessControlList.PublicRead;
|
||||
case PUBLIC_READ_WRITE -> CannedAccessControlList.PublicReadWrite;
|
||||
case PRIVATE -> CannedAccessControlList.Private;
|
||||
case AUTHENTICATED_READ -> CannedAccessControlList.AuthenticatedRead;
|
||||
default -> CannedAccessControlList.PublicRead;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setAcl(StorageAcl acl, String... path) {
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
s3Client.setObjectAcl(config.getBucketName(), buildPath(path), convertAcl(acl));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -212,7 +207,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
@Override
|
||||
public boolean isExists(String... path) {
|
||||
try (S3Wrapper wrapper = getS3Client()) {
|
||||
AmazonS3Client s3Client = wrapper.getS3Client();
|
||||
AmazonS3Client s3Client = wrapper.s3Client();
|
||||
return s3Client.doesObjectExist(config.getBucketName(), buildPath(path));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
@@ -242,18 +237,7 @@ public class AwsOssAdapter extends AStorageAdapter {
|
||||
return StorageUtil.getRelativePath(path, config.getPrefix());
|
||||
}
|
||||
|
||||
public static class S3Wrapper implements AutoCloseable {
|
||||
private final AmazonS3Client s3Client;
|
||||
|
||||
public S3Wrapper(AmazonS3Client s3Client) {
|
||||
this.s3Client = s3Client;
|
||||
}
|
||||
|
||||
// 提供对原始对象的方法访问
|
||||
public AmazonS3Client getS3Client() {
|
||||
return s3Client;
|
||||
}
|
||||
|
||||
public record S3Wrapper(AmazonS3Client s3Client) implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
s3Client.shutdown();
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package com.ycwl.basic.storage.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum StorageAcl {
|
||||
PUBLIC_READ("public-read"),
|
||||
PRIVATE("private"),
|
||||
@@ -12,7 +15,4 @@ public enum StorageAcl {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user