mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 23:45:11 +01:00
feat(api): reAnalyze library
This commit is contained in:
parent
94faf157d6
commit
fa65e94ae6
2 changed files with 22 additions and 2 deletions
|
|
@ -27,6 +27,8 @@ interface BookRepository : JpaRepository<Book, Long>, JpaSpecificationExecutor<B
|
|||
@QueryHints(QueryHint(name = CACHEABLE, value = "true"))
|
||||
fun findBySeriesLibraryIn(seriesLibrary: Collection<Library>, pageable: Pageable): Page<Book>
|
||||
|
||||
fun findBySeriesLibraryIn(seriesLibrary: Collection<Library>): List<Book>
|
||||
|
||||
fun findByUrl(url: URL): Book?
|
||||
fun findAllByMediaStatus(status: Media.Status): List<Book>
|
||||
fun findAllByMediaThumbnailIsNull(): List<Book>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import org.gotson.komga.domain.model.DirectoryNotFoundException
|
|||
import org.gotson.komga.domain.model.DuplicateNameException
|
||||
import org.gotson.komga.domain.model.Library
|
||||
import org.gotson.komga.domain.model.PathContainedInPath
|
||||
import org.gotson.komga.domain.persistence.BookRepository
|
||||
import org.gotson.komga.domain.persistence.LibraryRepository
|
||||
import org.gotson.komga.domain.service.AsyncOrchestrator
|
||||
import org.gotson.komga.domain.service.LibraryLifecycle
|
||||
import org.gotson.komga.infrastructure.security.KomgaPrincipal
|
||||
import org.springframework.data.domain.Sort
|
||||
|
|
@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.ResponseStatus
|
|||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.concurrent.RejectedExecutionException
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
|
|
@ -33,7 +36,9 @@ private val logger = KotlinLogging.logger {}
|
|||
@RequestMapping("api/v1/libraries", produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
class LibraryController(
|
||||
private val libraryLifecycle: LibraryLifecycle,
|
||||
private val libraryRepository: LibraryRepository
|
||||
private val libraryRepository: LibraryRepository,
|
||||
private val bookRepository: BookRepository,
|
||||
private val asyncOrchestrator: AsyncOrchestrator
|
||||
) {
|
||||
|
||||
@GetMapping
|
||||
|
|
@ -83,6 +88,19 @@ class LibraryController(
|
|||
libraryLifecycle.deleteLibrary(it)
|
||||
} ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
}
|
||||
|
||||
@PostMapping("{libraryId}/analyze")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ResponseStatus(HttpStatus.ACCEPTED)
|
||||
fun analyze(@PathVariable libraryId: Long) {
|
||||
libraryRepository.findByIdOrNull(libraryId)?.let { library ->
|
||||
try {
|
||||
asyncOrchestrator.reAnalyzeBooks(bookRepository.findBySeriesLibraryIn(listOf(library)))
|
||||
} catch (e: RejectedExecutionException) {
|
||||
throw ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "Another book analysis task is already running")
|
||||
}
|
||||
} ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
data class LibraryCreationDto(
|
||||
|
|
|
|||
Loading…
Reference in a new issue