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?
|
@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
|
||||||
|
|||||||
Reference in New Issue
Block a user