From 7de42b285a98ef182c5187720837f2342c17d851 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 20 Oct 2021 13:41:07 +0330 Subject: [PATCH 1/2] Fix storage controller --- .../co/nilin/opex/storage/app/controller/FileController.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt b/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt index b8f8d6d8d..c238326f1 100644 --- a/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt +++ b/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt @@ -16,6 +16,8 @@ import java.nio.file.Paths @RestController class FileController(private val storageService: StorageService) { + data class FileUploadResponse(val path: String) + @PostMapping("/{uid}") suspend fun fileUpload( @PathVariable("uid") uid: String, @@ -24,14 +26,13 @@ class FileController(private val storageService: StorageService) { ): Any { if (securityContext.authentication.name != uid) throw OpexException(OpexError.UnAuthorized) file.awaitFirstOrNull().apply { - data class Response(val uri: String) if (this == null) throw OpexException(OpexError.BadRequest, "File Not Provided") val ext = this.filename().replace(Regex(".+(?=\\..+)"), "") - if (ext !in listOf(".jpg", ".jpeg", ".png", ".mp4", ".mov")) + if (ext !in listOf(".jpg", ".jpeg", ".png", ".mp4", ".mov", ".pdf", ".svg")) throw OpexException(OpexError.BadRequest, "Invalid File Format") val path = Paths.get("").resolve("/opex-storage/$uid/${this.filename()}").toString() storageService.store(path, this) - return Response(path) + return FileUploadResponse("/$uid/${this.filename()}\"") } } From 8b14891b3161f3da7544538294146fa1ff872b65 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 20 Oct 2021 13:52:33 +0330 Subject: [PATCH 2/2] Make file extension case insensitive --- .../co/nilin/opex/storage/app/controller/FileController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt b/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt index c238326f1..0bb8ba89b 100644 --- a/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt +++ b/Storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt @@ -28,7 +28,7 @@ class FileController(private val storageService: StorageService) { file.awaitFirstOrNull().apply { if (this == null) throw OpexException(OpexError.BadRequest, "File Not Provided") val ext = this.filename().replace(Regex(".+(?=\\..+)"), "") - if (ext !in listOf(".jpg", ".jpeg", ".png", ".mp4", ".mov", ".pdf", ".svg")) + if (ext.toLowerCase() !in listOf(".jpg", ".jpeg", ".png", ".mp4", ".mov", ".pdf", ".svg")) throw OpexException(OpexError.BadRequest, "Invalid File Format") val path = Paths.get("").resolve("/opex-storage/$uid/${this.filename()}").toString() storageService.store(path, this)