feat(backend): cover/file/pages endpoints — immutable URLs, Range, disk+redis caches
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -10,15 +11,20 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"booklib/internal/bookfile"
|
||||
"booklib/internal/store"
|
||||
)
|
||||
|
||||
func (a *api) getBookRow(c *gin.Context, id int64) (store.Book, bool) {
|
||||
b, perr := a.st.GetBook(c, id)
|
||||
if perr != nil {
|
||||
err(c, http.StatusNotFound, "not_found", "no such book")
|
||||
b, e := a.st.GetBook(c, id)
|
||||
if e != nil {
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
err(c, http.StatusNotFound, "not_found", "no such book")
|
||||
return store.Book{}, false
|
||||
}
|
||||
err(c, http.StatusInternalServerError, "internal", "db error")
|
||||
return store.Book{}, false
|
||||
}
|
||||
return b, true
|
||||
|
||||
Reference in New Issue
Block a user