feat(backend): cover/file/pages endpoints — immutable URLs, Range, disk+redis caches

This commit is contained in:
2026-09-05 00:48:40 +08:00
parent 249619b857
commit 0946f6be5a
5 changed files with 340 additions and 3 deletions
+9 -3
View File
@@ -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