From 6fbde83ecdae239a1f0416adc469c777e67b7a01 Mon Sep 17 00:00:00 2001 From: Sumer Jabri Date: Thu, 25 Jan 2024 10:43:55 -0500 Subject: [PATCH] Updated S3Item to include `prefix` (#3468) * 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. --- .../impl/v2/service/aws/s3/AwsS3ServiceImpl.java | 6 +++--- .../craftercms/studio/model/aws/s3/S3Item.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/aws/s3/AwsS3ServiceImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/aws/s3/AwsS3ServiceImpl.java index a77f8bb06c..188ffa2f2e 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/aws/s3/AwsS3ServiceImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/aws/s3/AwsS3ServiceImpl.java @@ -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()); } /** @@ -158,7 +158,7 @@ public List 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); @@ -167,7 +167,7 @@ public List 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); diff --git a/src/main/java/org/craftercms/studio/model/aws/s3/S3Item.java b/src/main/java/org/craftercms/studio/model/aws/s3/S3Item.java index a4d9687b49..15dd9987fd 100644 --- a/src/main/java/org/craftercms/studio/model/aws/s3/S3Item.java +++ b/src/main/java/org/craftercms/studio/model/aws/s3/S3Item.java @@ -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() { @@ -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; + } }