Validate room image storage path
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
This commit is contained in:
@@ -17,6 +17,18 @@ class RoomImageStorage(
|
||||
@Value("\${storage.rooms.root:/home/androidlover5842/docs/rooms}")
|
||||
private val rootPath: String
|
||||
) {
|
||||
init {
|
||||
val root = Paths.get(rootPath)
|
||||
try {
|
||||
Files.createDirectories(root)
|
||||
} catch (ex: Exception) {
|
||||
throw IllegalStateException("Room image root not writable: $rootPath", ex)
|
||||
}
|
||||
if (!Files.isWritable(root)) {
|
||||
throw IllegalStateException("Room image root not writable: $rootPath")
|
||||
}
|
||||
}
|
||||
|
||||
fun store(propertyId: UUID, roomId: UUID, file: MultipartFile): StoredRoomImage {
|
||||
val contentType = file.contentType ?: ""
|
||||
if (!contentType.startsWith("image/")) {
|
||||
@@ -27,7 +39,11 @@ class RoomImageStorage(
|
||||
val ext = extensionFor(contentType, originalName)
|
||||
|
||||
val dir = Paths.get(rootPath, propertyId.toString(), roomId.toString())
|
||||
try {
|
||||
Files.createDirectories(dir)
|
||||
} catch (ex: Exception) {
|
||||
throw IllegalStateException("Failed to create room image directory: $dir", ex)
|
||||
}
|
||||
val base = UUID.randomUUID().toString() + "_" + OffsetDateTime.now().toEpochSecond()
|
||||
val originalPath = dir.resolve("$base.$ext")
|
||||
val originalTmp = dir.resolve("$base.$ext.tmp")
|
||||
|
||||
Reference in New Issue
Block a user