Skip to content

Commit

Permalink
Updated S3Item to hold the bucket name in addition to the other field…
Browse files Browse the repository at this point in the history
…s to help maintain backward compatibility. (#3462)
  • Loading branch information
sumerjabri committed Jan 23, 2024
1 parent 346b848 commit 024d978
Show file tree
Hide file tree
Showing 2 changed files with 18 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);
return new S3Item(filename, createUrl(profileId, relativeKey), false, inputBucket);
}

/**
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);
return new S3Item(StringUtils.removeEnd(relativeKey, delimiter), relativeKey, true, profile.getBucketName());
})
.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);
return new S3Item(relativeKey, createUrl(profileId, relativeKey), false, profile.getBucketName());
})
.forEach(items::add);

Expand Down
16 changes: 15 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 @@ -37,10 +37,16 @@ public class S3Item {
*/
protected boolean folder;

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

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

public String getName() {
Expand All @@ -67,4 +73,12 @@ public void setFolder(final boolean folder) {
this.folder = folder;
}

public String getBucketName() {
return bucketName;
}

public void setBucketName(final String bucketName) {
this.bucketName = bucketName;
}

}

0 comments on commit 024d978

Please sign in to comment.