Skip to content

Commit

Permalink
Updated S3Item to include prefix (#3468)
Browse files Browse the repository at this point in the history
* Updated S3Item to hold the bucket name in addition to the other fields to help maintain backward compatibility.

* Updated S3Item to hold the prefix in addition to the other fields to help maintain backward compatibility.
  • Loading branch information
sumerjabri committed Jan 25, 2024
1 parent 6721079 commit 6fbde83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public S3Item uploadItem(@SiteId String siteId,

AwsUtils.uploadStream(inputBucket, fullKey, s3Client, partSize, filename, content);

return new S3Item(filename, createUrl(profileId, relativeKey), false, inputBucket);
return new S3Item(filename, createUrl(profileId, relativeKey), false, inputBucket, profile.getPrefix());
}

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ public List<S3Item> listItems(@SiteId String siteId,
result.getCommonPrefixes().stream()
.map(p -> {
String relativeKey = StringUtils.removeStart(p, profile.getPrefix());
return new S3Item(StringUtils.removeEnd(relativeKey, delimiter), relativeKey, true, profile.getBucketName());
return new S3Item(StringUtils.removeEnd(relativeKey, delimiter), relativeKey, true, profile.getBucketName(), profile.getPrefix());
})
.forEach(items::add);

Expand All @@ -167,7 +167,7 @@ public List<S3Item> listItems(@SiteId String siteId,
MimeType.valueOf(StudioUtils.getMimeType(o.getKey())).isCompatibleWith(filerType))
.map(o -> {
String relativeKey = StringUtils.removeStart(o.getKey(), profile.getPrefix());
return new S3Item(relativeKey, createUrl(profileId, relativeKey), false, profile.getBucketName());
return new S3Item(relativeKey, createUrl(profileId, relativeKey), false, profile.getBucketName(), profile.getPrefix());
})
.forEach(items::add);

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/craftercms/studio/model/aws/s3/S3Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ public class S3Item {
*/
protected String bucketName;

public S3Item(final String name, final String url, final boolean folder, final String bucketName) {
/**
* The prefix of the S3 bucket (if any).
*/
protected String prefix;

public S3Item(final String name, final String url, final boolean folder, final String bucketName, final String prefix) {
this.name = name;
this.url = url;
this.folder = folder;
this.bucketName = bucketName;
this.prefix = prefix;
}

public String getName() {
Expand Down Expand Up @@ -81,4 +87,11 @@ public void setBucketName(final String bucketName) {
this.bucketName = bucketName;
}

public String getPrefix() {
return prefix;
}

public void setPrefix(final String prefix) {
this.prefix = prefix;
}
}

0 comments on commit 6fbde83

Please sign in to comment.