Fix NPE in ImageService when contentId of Image entity is null

This commit is contained in:
grimsi
2025-07-21 10:09:22 +02:00
parent 3cecdd558a
commit 32731b3f22
3 changed files with 8 additions and 6 deletions
@@ -105,7 +105,7 @@ class GameService(
imageService.downloadIfNew(it)
}
} catch (e: Exception) {
log.error { "Error downloading images for game: ${e.message}" }
log.error { "Error downloading images for game '${game.title}' (${game.id}): ${e.message}" }
log.debug(e) {}
null
}
@@ -376,7 +376,7 @@ class LibraryScanService(
game
} catch (e: Exception) {
log.error { "Error downloading images for game: ${e.message}" }
log.error { "Error downloading images for game '${game.title}' (${game.id}): ${e.message}" }
log.debug(e) {}
null
} finally {
@@ -1,10 +1,10 @@
package org.gameyfin.app.media
import org.apache.tika.Tika
import org.apache.tika.io.TikaInputStream
import org.gameyfin.app.games.entities.Image
import org.gameyfin.app.games.entities.ImageType
import org.gameyfin.app.games.repositories.ImageContentStore
import org.apache.tika.Tika
import org.apache.tika.io.TikaInputStream
import org.gameyfin.app.games.repositories.ImageRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
@@ -22,8 +22,10 @@ class ImageService(
fun downloadIfNew(image: Image) {
if (image.originalUrl == null) throw IllegalArgumentException("Image must have an original URL")
imageRepository.findByOriginalUrl(image.originalUrl)?.let {
imageContentStore.associate(image, it.contentId)
val existingImage = imageRepository.findByOriginalUrl(image.originalUrl)
if (existingImage != null && existingImage.contentId != null) {
imageContentStore.associate(image, existingImage.contentId)
return
}