feat(S3): support PutObjectResult, fix key / name

- add S3File creation with `PutObjectResult` support.
- properly extract name of file / folder from key.
This commit is contained in:
Manuel Jenny 2021-04-20 13:38:49 +02:00
parent fe21e3988d
commit c63db47e56
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18

View File

@ -1,25 +1,35 @@
package org.cryptomator.data.cloud.s3;
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import org.cryptomator.util.Optional;
class S3CloudNodeFactory {
private static final String SUFFIX = "/";
public static S3File file(S3Folder parent, S3ObjectSummary file) {
return new S3File(parent, file.getKey(), getNodePath(parent, file.getKey()), Optional.ofNullable(file.getSize()), Optional.ofNullable(file.getLastModified()));
String name = getNameFromKey(file.getKey());
return new S3File(parent, name, getNodePath(parent, name), Optional.ofNullable(file.getSize()), Optional.ofNullable(file.getLastModified()));
}
public static S3File file(S3Folder parent, String name, PutObjectResult file) {
return new S3File(parent, name, getNodePath(parent, name), Optional.ofNullable(file.getMetadata().getContentLength()), Optional.ofNullable(file.getMetadata().getLastModified()));
}
public static S3File file(S3Folder parent, String name, Optional<Long> size) {
return new S3File(parent, name, getNodePath(parent, name), size, Optional.empty());
}
public static S3File file(S3Folder folder, String name, Optional<Long> size, String path) {
return new S3File(folder, name, path, size, Optional.empty());
public static S3File file(S3Folder parent, String name, Optional<Long> size, String path) {
return new S3File(parent, name, path, size, Optional.empty());
}
public static S3Folder folder(S3Folder parent, S3ObjectSummary folder) {
return new S3Folder(parent, folder.getKey(), getNodePath(parent, folder.getKey()));
String name = getNameFromKey(folder.getKey());
return new S3Folder(parent, name, getNodePath(parent, name));
}
public static S3Folder folder(S3Folder parent, String name) {
@ -30,12 +40,16 @@ class S3CloudNodeFactory {
return new S3Folder(parent, name, path);
}
public static String getNodePath(S3Folder parent, String name) {
return parent.getPath() + "/" + name;
private static String getNodePath(S3Folder parent, String name) {
return parent.getPath() + SUFFIX + name;
}
private static String getNameFromKey(String key) {
return key.substring(key.lastIndexOf(SUFFIX) + 1);
}
public static S3Node from(S3Folder parent, S3ObjectSummary objectSummary) {
if (objectSummary.getKey().endsWith("/")) {
if (objectSummary.getKey().endsWith(SUFFIX)) {
return folder(parent, objectSummary);
} else {
return file(parent, objectSummary);