Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated S3Item to include prefix #3468

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}