- H now holds only small port interfaces (UserStore/LibraryStore/BookStore/ ProgressStore/BookmarkStore/RateLimiter/Scanner/Media/UploadSessions); NewRouter is the composition root distributing *store.Store and *redispkg.R - ports.Media gains EnsurePage; ChaptersOf returns ports.Chapter (media's local duplicate dropped); *media.M now provably satisfies ports.Media; ports.UploadSessions gains LibraryID for root validation before Complete - content.go: duplicated page-index cache + cover self-heal + page extract logic removed in favor of media service — same redis keys, same contract; path traversal check stays in handler (403 semantics preserved) - getLibrary/getLibRow merged into getLib(c, id); idParam helper dedupes :id parsing; isUnique replaced by ports.IsUniqueViolation (Task 28 partial) - main.go assembles media + upload and passes upload.U as scanner Sweeper Full gate green: gofmt, vet, go test -p 1 (real PG+Redis, 0 skip)
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *H) PutProgress(c *gin.Context) {
|
|
b, ok := h.bookFromParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req struct {
|
|
Locator json.RawMessage `json:"locator"`
|
|
Percent float64 `json:"percent"`
|
|
}
|
|
if e := c.ShouldBindJSON(&req); e != nil {
|
|
err(c, http.StatusBadRequest, "bad_request", "json body required")
|
|
return
|
|
}
|
|
if req.Percent < 0 || req.Percent > 1 {
|
|
err(c, http.StatusBadRequest, "bad_request", "percent must be in [0,1]")
|
|
return
|
|
}
|
|
if len(req.Locator) == 0 {
|
|
req.Locator = []byte("{}")
|
|
}
|
|
if !json.Valid(req.Locator) {
|
|
err(c, http.StatusBadRequest, "bad_request", "locator must be valid json")
|
|
return
|
|
}
|
|
if e := h.progress.UpsertProgress(c, uid(c), b.LibraryID, b.Path, req.Locator, req.Percent); e != nil {
|
|
dbErr(c, e)
|
|
return
|
|
}
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
|
|
func (h *H) ListProgress(c *gin.Context) {
|
|
rows, e := h.progress.ListProgress(c, uid(c))
|
|
if e != nil {
|
|
dbErr(c, e)
|
|
return
|
|
}
|
|
out := make([]gin.H, 0, len(rows))
|
|
for _, p := range rows {
|
|
out = append(out, gin.H{
|
|
"library_id": p.LibraryID, "library": p.LibraryName, "path": p.BookPath,
|
|
"title": p.Title, "locator": json.RawMessage(p.Locator),
|
|
"percent": p.Percent, "updated_at": p.UpdatedAt.Format(time.RFC3339),
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, out)
|
|
}
|