Prune room images missing files on list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-01-27 23:01:58 +05:30
parent 5868586b09
commit e4c38a699f

View File

@@ -55,8 +55,26 @@ class RoomImages(
@AuthenticationPrincipal principal: MyPrincipal? @AuthenticationPrincipal principal: MyPrincipal?
): List<RoomImageResponse> { ): List<RoomImageResponse> {
ensureRoom(propertyId, roomId) ensureRoom(propertyId, roomId)
return roomImageRepo.findByRoomIdOrdered(roomId) val images = roomImageRepo.findByRoomIdOrdered(roomId).toMutableList()
.map { it.toResponse(publicBaseUrl) } if (images.isEmpty()) return emptyList()
val missing = mutableListOf<RoomImage>()
val present = mutableListOf<RoomImage>()
for (img in images) {
val originalExists = Files.exists(Paths.get(img.originalPath))
if (!originalExists) {
missing.add(img)
try {
Files.deleteIfExists(Paths.get(img.thumbnailPath))
} catch (_: Exception) {
}
} else {
present.add(img)
}
}
if (missing.isNotEmpty()) {
roomImageRepo.deleteAll(missing)
}
return present.map { it.toResponse(publicBaseUrl) }
} }
@PostMapping @PostMapping