mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 08:32:25 +01:00
fix(api): book import would return incorrect matched series
This commit is contained in:
parent
4a0e4047a8
commit
10e0bded9d
2 changed files with 56 additions and 8 deletions
|
|
@ -72,19 +72,23 @@ class TransientBookLifecycle(
|
|||
seriesMetadataProviders
|
||||
.flatMap {
|
||||
buildList {
|
||||
if (it.supportsAppendVolume) add(it.getSeriesMetadataFromBook(bookWithMedia, true)?.title)
|
||||
add(it.getSeriesMetadataFromBook(bookWithMedia, false)?.title)
|
||||
if (it.supportsAppendVolume) add(it.getSeriesMetadataFromBook(bookWithMedia, true)?.title?.ifBlank { null })
|
||||
add(it.getSeriesMetadataFromBook(bookWithMedia, false)?.title?.ifBlank { null })
|
||||
}
|
||||
}.filterNotNull()
|
||||
|
||||
val exactSearch = SearchCondition.AnyOfSeries(seriesNamesFromMetadata.map { SearchCondition.Title(SearchOperator.Is(it)) })
|
||||
val exactMatches = seriesRepository.findAll(exactSearch, SearchContext.ofAnonymousUser(), Pageable.unpaged())
|
||||
val series =
|
||||
if (!exactMatches.isEmpty) {
|
||||
exactMatches.content.first()
|
||||
if (seriesNamesFromMetadata.isNotEmpty()) {
|
||||
val exactSearch = SearchCondition.AnyOfSeries(seriesNamesFromMetadata.map { SearchCondition.Title(SearchOperator.Is(it)) })
|
||||
val exactMatches = seriesRepository.findAll(exactSearch, SearchContext.ofAnonymousUser(), Pageable.unpaged())
|
||||
if (!exactMatches.isEmpty) {
|
||||
exactMatches.content.first()
|
||||
} else {
|
||||
val containsSearch = SearchCondition.AnyOfSeries(seriesNamesFromMetadata.map { SearchCondition.Title(SearchOperator.Contains(it)) })
|
||||
seriesRepository.findAll(containsSearch, SearchContext.ofAnonymousUser(), Pageable.unpaged()).content.firstOrNull()
|
||||
}
|
||||
} else {
|
||||
val containsSearch = SearchCondition.AnyOfSeries(seriesNamesFromMetadata.map { SearchCondition.Title(SearchOperator.Contains(it)) })
|
||||
seriesRepository.findAll(containsSearch, SearchContext.ofAnonymousUser(), Pageable.unpaged()).content.firstOrNull()
|
||||
null
|
||||
}
|
||||
|
||||
return series?.id to number
|
||||
|
|
|
|||
|
|
@ -68,4 +68,48 @@ class TransientBookLifecycleTest(
|
|||
assertThat(seriesId).isEqualTo(seriesExact.id)
|
||||
assertThat(number).isEqualTo(15F)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when getting metadata for transient book without series then no series is matched`() {
|
||||
seriesLifecycle.createSeries(makeSeries("Batman and Robin", libraryId = library.id))
|
||||
val seriesExact = makeSeries("Batman", libraryId = library.id)
|
||||
seriesLifecycle.createSeries(seriesExact)
|
||||
seriesLifecycle.createSeries(makeSeries("Batman and Robin (2022)", libraryId = library.id))
|
||||
|
||||
val book =
|
||||
TransientBook(
|
||||
makeBook("whatever"),
|
||||
Media(),
|
||||
)
|
||||
|
||||
every { mockProvider.getBookMetadataFromBook(any()) } returns BookMetadataPatch(null, null, null, null, null, null, null, null, null, emptyList())
|
||||
every { mockProvider.getSeriesMetadataFromBook(any(), any()) } returns SeriesMetadataPatch(null, null, null, null, null, null, null, null, null, null, emptySet())
|
||||
|
||||
val (seriesId, number) = transientBookLifecycle.getMetadata(book)
|
||||
|
||||
assertThat(seriesId).isNull()
|
||||
assertThat(number).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when getting metadata for transient book with blank series then no series is matched`() {
|
||||
seriesLifecycle.createSeries(makeSeries("Batman and Robin", libraryId = library.id))
|
||||
val seriesExact = makeSeries("Batman", libraryId = library.id)
|
||||
seriesLifecycle.createSeries(seriesExact)
|
||||
seriesLifecycle.createSeries(makeSeries("Batman and Robin (2022)", libraryId = library.id))
|
||||
|
||||
val book =
|
||||
TransientBook(
|
||||
makeBook("whatever"),
|
||||
Media(),
|
||||
)
|
||||
|
||||
every { mockProvider.getBookMetadataFromBook(any()) } returns BookMetadataPatch(null, null, null, null, null, null, null, null, null, emptyList())
|
||||
every { mockProvider.getSeriesMetadataFromBook(any(), any()) } returns SeriesMetadataPatch(" ", null, null, null, null, null, null, null, null, null, emptySet())
|
||||
|
||||
val (seriesId, number) = transientBookLifecycle.getMetadata(book)
|
||||
|
||||
assertThat(seriesId).isNull()
|
||||
assertThat(number).isNull()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue