Skip to content

Commit

Permalink
feat(api): reAnalyze library
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Jan 6, 2020
1 parent 94faf15 commit fa65e94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -32,8 +35,10 @@ private val logger = KotlinLogging.logger {}
@RestController
@RequestMapping("api/v1/libraries", produces = [MediaType.APPLICATION_JSON_VALUE])
class LibraryController(
private val libraryLifecycle: LibraryLifecycle,
private val libraryRepository: LibraryRepository
private val libraryLifecycle: LibraryLifecycle,
private val libraryRepository: LibraryRepository,
private val bookRepository: BookRepository,
private val asyncOrchestrator: AsyncOrchestrator
) {

@GetMapping
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fa65e94

Please sign in to comment.