Skip to content

Commit 41d001a

Browse files
committed
Add constant for workspace files base folder and update S3 object paths accordingly
1 parent fe68264 commit 41d001a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import org.springframework.web.multipart.MultipartFile
5353
import software.amazon.awssdk.services.s3.S3Client
5454
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request
5555

56+
private const val WORKSPACE_FILES_BASE_FOLDER = "workspace-files"
57+
5658
@Service
5759
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
5860
@Suppress("TooManyFunctions")
@@ -240,7 +242,9 @@ internal class WorkspaceServiceImpl(
240242
fileName)
241243
return InputStreamResource(
242244
s3Template
243-
.download(csmPlatformProperties.s3.bucketName, "$organizationId/$workspaceId/$fileName")
245+
.download(
246+
csmPlatformProperties.s3.bucketName,
247+
"$organizationId/$workspaceId/$WORKSPACE_FILES_BASE_FOLDER/$fileName")
244248
.inputStream)
245249
}
246250

@@ -280,7 +284,8 @@ internal class WorkspaceServiceImpl(
280284
fileRelativeDestinationBuilder.append(file.originalFilename)
281285
}
282286
}
283-
val objectKey = "$organizationId/$workspaceId/$fileRelativeDestinationBuilder"
287+
val objectKey =
288+
"$organizationId/$workspaceId/$WORKSPACE_FILES_BASE_FOLDER/$fileRelativeDestinationBuilder"
284289

285290
if (!overwrite && s3Template.objectExists(csmPlatformProperties.s3.bucketName, objectKey)) {
286291
throw IllegalArgumentException(
@@ -319,7 +324,7 @@ internal class WorkspaceServiceImpl(
319324
}
320325

321326
private fun getWorkspaceFiles(organizationId: String, workspaceId: String): List<WorkspaceFile> {
322-
val prefix = "${organizationId}/${workspaceId}/"
327+
val prefix = "${organizationId}/${workspaceId}/$WORKSPACE_FILES_BASE_FOLDER/"
323328
val listObjectsRequest =
324329
ListObjectsV2Request.builder()
325330
.bucket(csmPlatformProperties.s3.bucketName)
@@ -347,7 +352,8 @@ internal class WorkspaceServiceImpl(
347352
fileName)
348353

349354
s3Template.deleteObject(
350-
csmPlatformProperties.s3.bucketName, "$organizationId/${workspace.id}/$fileName")
355+
csmPlatformProperties.s3.bucketName,
356+
"$organizationId/${workspace.id}/$WORKSPACE_FILES_BASE_FOLDER/$fileName")
351357
}
352358

353359
override fun deleteAllS3WorkspaceObjects(organizationId: String, workspace: Workspace) {

0 commit comments

Comments
 (0)