default sort for books by name ignoring case

removed natSort of books during scan, as order get messed up anyway with updates
fixed serie that was not persisting fileLastModified date on rescans
This commit is contained in:
Gauthier Roebroeck 2019-08-21 23:07:06 +08:00
parent 7e26f85159
commit db7e5e3c53
3 changed files with 22 additions and 18 deletions

View file

@ -1,7 +1,6 @@
package org.gotson.komga.domain.service
import mu.KotlinLogging
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
import org.apache.commons.io.FilenameUtils
import org.apache.commons.lang3.time.DurationFormatUtils
import org.gotson.komga.domain.model.Book
@ -13,7 +12,6 @@ import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import java.time.LocalDateTime
import java.time.ZoneId
import java.util.*
import kotlin.streams.asSequence
import kotlin.streams.toList
import kotlin.system.measureTimeMillis
@ -25,8 +23,6 @@ class FileSystemScanner {
val supportedExtensions = listOf("cbz", "zip", "cbr", "rar")
private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()
fun scanRootFolder(root: Path): List<Serie> {
logger.info { "Scanning folder: $root" }
logger.info { "Supported extensions: $supportedExtensions" }
@ -48,9 +44,6 @@ class FileSystemScanner {
fileLastModified = it.getUpdatedTime()
)
}.toList()
.sortedWith(
compareBy(natSortComparator) { it.name }
)
if (books.isNullOrEmpty()) return@mapNotNull null
Serie(
name = dir.fileName.toString(),

View file

@ -52,8 +52,8 @@ class LibraryManager(
if (newSerie.fileLastModified != existingSerie.fileLastModified) {
logger.info { "Serie changed on disk, updating: ${newSerie.url}" }
existingSerie.name = newSerie.name
existingSerie.fileLastModified = newSerie.fileLastModified
var anyBookchanged = false
// update list of books with existing entities if they exist
existingSerie.books = newSerie.books.map { newBook ->
val existingBook = bookRepository.findByUrl(newBook.url) ?: newBook
@ -63,15 +63,10 @@ class LibraryManager(
existingBook.fileLastModified = newBook.fileLastModified
existingBook.name = newBook.name
existingBook.metadata.reset()
anyBookchanged = true
}
existingBook
}.toMutableList()
// propagate modification of any of the books to the serie, so that LastModifiedDate is updated
if (anyBookchanged)
auditingHandler.markModified(existingSerie)
serieRepository.save(existingSerie)
}
}

View file

@ -23,6 +23,9 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ResponseStatusException
import java.io.File
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
@RestController
@RequestMapping("api/v1/series")
@ -87,10 +90,16 @@ class SerieController(
page: Pageable
): Page<BookDto> {
if (!serieRepository.existsById(id)) throw ResponseStatusException(HttpStatus.NOT_FOUND)
val pageRequest = PageRequest.of(
page.pageNumber,
page.pageSize,
if (page.sort.isSorted) page.sort
else Sort.by(Sort.Order.asc("name").ignoreCase())
)
return if (readyFilter) {
bookRepository.findAllByMetadataStatusAndSerieId(Status.READY, id, page)
bookRepository.findAllByMetadataStatusAndSerieId(Status.READY, id, pageRequest)
} else {
bookRepository.findAllBySerieId(id, page)
bookRepository.findAllBySerieId(id, pageRequest)
}.map { it.toDto() }
}
@ -174,13 +183,15 @@ class SerieController(
data class SerieDto(
val id: Long,
val name: String,
val url: String
val url: String,
val lastModified: LocalDateTime?
)
fun Serie.toDto() = SerieDto(
id = id,
name = name,
url = url.toString()
url = url.toString(),
lastModified = lastModifiedDate?.toUTC()
)
@ -188,6 +199,7 @@ data class BookDto(
val id: Long,
val name: String,
val url: String,
val lastModified: LocalDateTime?,
val metadata: BookMetadataDto
)
@ -201,6 +213,7 @@ fun Book.toDto() =
id = id,
name = name,
url = url.toString(),
lastModified = lastModifiedDate?.toUTC(),
metadata = BookMetadataDto(
status = metadata.status.toString(),
mediaType = metadata.mediaType ?: ""
@ -211,4 +224,7 @@ data class PageDto(
val number: Int,
val fileName: String,
val mediaType: String
)
)
fun LocalDateTime.toUTC() =
atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()