Validate room image storage path
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s

This commit is contained in:
androidlover5842
2026-01-27 16:43:07 +05:30
parent 0cb6b8b435
commit 5bfbd295c9

View File

@@ -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())
Files.createDirectories(dir)
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")