Prune room images missing files on list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -55,8 +55,26 @@ class RoomImages(
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
): List<RoomImageResponse> {
|
||||
ensureRoom(propertyId, roomId)
|
||||
return roomImageRepo.findByRoomIdOrdered(roomId)
|
||||
.map { it.toResponse(publicBaseUrl) }
|
||||
val images = roomImageRepo.findByRoomIdOrdered(roomId).toMutableList()
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user