Skip to content

Commit

Permalink
add endpoint aliases so that all opds feed urls use the same base path
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Dec 19, 2019
1 parent 659cea4 commit 37fa1d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ class OpdsController(
id = id.toString(),
content = "$name (${fileExtension().toUpperCase()}) (${fileSizeHumanReadable()})",
links = listOf(
OpdsLinkImageThumbnail("image/jpeg", "/api/v1/series/${series.id}/books/$id/thumbnail"),
OpdsLinkImage(metadata.pages[0].mediaType, "/api/v1/series/${series.id}/books/$id/pages/1"),
OpdsLinkFileAcquisition(metadata.mediaType, "/api/v1/series/${series.id}/books/$id/file/${fileName()}"),
OpdsLinkPageStreaming("image/jpeg", "/api/v1/series/${series.id}/books/$id/pages/{pageNumber}?convert=jpeg&zero_based=true", metadata.pages.size)
OpdsLinkImageThumbnail("image/jpeg", "${ROUTE_BASE}books/$id/thumbnail"),
OpdsLinkImage(metadata.pages[0].mediaType, "${ROUTE_BASE}books/$id/pages/1"),
OpdsLinkFileAcquisition(metadata.mediaType, "${ROUTE_BASE}books/$id/file/${fileName()}"),
OpdsLinkPageStreaming("image/jpeg", "${ROUTE_BASE}books/$id/pages/{pageNumber}?convert=jpeg&zero_based=true", metadata.pages.size)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ import java.util.concurrent.TimeUnit
private val logger = KotlinLogging.logger {}

@RestController
@RequestMapping("api/v1", produces = [MediaType.APPLICATION_JSON_VALUE])
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
class BookController(
private val libraryRepository: LibraryRepository,
private val seriesRepository: SeriesRepository,
private val bookRepository: BookRepository,
private val bookLifecycle: BookLifecycle
) {

@GetMapping("books")
@GetMapping("api/v1/books")
fun getAllBooks(
@AuthenticationPrincipal principal: KomgaPrincipal,
@RequestParam(name = "search", required = false) searchTerm: String?,
Expand Down Expand Up @@ -89,7 +89,7 @@ class BookController(
}


@GetMapping("books/latest")
@GetMapping("api/v1/books/latest")
fun getLatestSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
page: Pageable
Expand All @@ -109,14 +109,14 @@ class BookController(


@Deprecated("since 0.9.0 the /books/{bookId} is preferred")
@GetMapping("series/{seriesId}/books/{bookId}")
@GetMapping("api/v1/series/{seriesId}/books/{bookId}")
fun getOneBookFromSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable seriesId: Long,
@PathVariable bookId: Long
): BookDto = getOneBook(principal, bookId)

@GetMapping("books/{bookId}")
@GetMapping("api/v1/books/{bookId}")
fun getOneBook(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable bookId: Long
Expand All @@ -128,14 +128,17 @@ class BookController(


@Deprecated("since 0.9.0 the /books/{bookId}/thumbnail is preferred")
@GetMapping(value = ["series/{seriesId}/books/{bookId}/thumbnail"], produces = [MediaType.IMAGE_PNG_VALUE])
@GetMapping(value = ["api/v1/series/{seriesId}/books/{bookId}/thumbnail"], produces = [MediaType.IMAGE_PNG_VALUE])
fun getBookThumbnailFromSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable seriesId: Long,
@PathVariable bookId: Long
): ResponseEntity<ByteArray> = getBookThumbnail(principal, bookId)

@GetMapping(value = ["books/{bookId}/thumbnail"], produces = [MediaType.IMAGE_PNG_VALUE])
@GetMapping(value = [
"api/v1/books/{bookId}/thumbnail",
"opds/v1.2/books/{bookId}/thumbnail"
], produces = [MediaType.IMAGE_PNG_VALUE])
fun getBookThumbnail(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable bookId: Long
Expand All @@ -154,8 +157,8 @@ class BookController(

@Deprecated("since 0.9.0 the /books/{bookId}/file is preferred")
@GetMapping(value = [
"series/{seriesId}/books/{bookId}/file",
"series/{seriesId}/books/{bookId}/file/*"
"api/v1/series/{seriesId}/books/{bookId}/file",
"api/v1/series/{seriesId}/books/{bookId}/file/*"
])
fun getBookFileFromSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
Expand All @@ -164,8 +167,9 @@ class BookController(
): ResponseEntity<ByteArray> = getBookFile(principal, bookId)

@GetMapping(value = [
"books/{bookId}/file",
"books/{bookId}/file/*"
"api/v1/books/{bookId}/file",
"api/v1/books/{bookId}/file/*",
"opds/v1.2/books/{bookId}/file/*"
])
fun getBookFile(
@AuthenticationPrincipal principal: KomgaPrincipal,
Expand All @@ -190,14 +194,14 @@ class BookController(


@Deprecated("since 0.9.0 the /books/{bookId}/pages is preferred")
@GetMapping("series/{seriesId}/books/{bookId}/pages")
@GetMapping("api/v1/series/{seriesId}/books/{bookId}/pages")
fun getBookPagesFromSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable seriesId: Long,
@PathVariable bookId: Long
): List<PageDto> = getBookPages(principal, bookId)

@GetMapping("books/{bookId}/pages")
@GetMapping("api/v1/books/{bookId}/pages")
fun getBookPages(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable bookId: Long
Expand All @@ -212,7 +216,7 @@ class BookController(


@Deprecated("since 0.9.0 the /books/{bookId}/page/{pageNumber} is preferred")
@GetMapping("series/{seriesId}/books/{bookId}/pages/{pageNumber}")
@GetMapping("api/v1/series/{seriesId}/books/{bookId}/pages/{pageNumber}")
fun getBookPageFromSeries(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable seriesId: Long,
Expand All @@ -222,7 +226,10 @@ class BookController(
@RequestParam(value = "zero_based", defaultValue = "false") zeroBasedIndex: Boolean
): ResponseEntity<ByteArray> = getBookPage(principal, bookId, pageNumber, convertTo, zeroBasedIndex)

@GetMapping("books/{bookId}/pages/{pageNumber}")
@GetMapping(value = [
"api/v1/books/{bookId}/pages/{pageNumber}",
"opds/v1.2/books/{bookId}/pages/{pageNumber}"
])
fun getBookPage(
@AuthenticationPrincipal principal: KomgaPrincipal,
@PathVariable bookId: Long,
Expand Down

0 comments on commit 37fa1d0

Please sign in to comment.