page + upload queue + folders

This commit is contained in:
m
2026-07-29 22:16:47 +02:00
parent 470474011d
commit 881767cfec
11 changed files with 248 additions and 41 deletions
+4 -1
View File
@@ -1,6 +1,8 @@
package handler
import (
"database/sql"
"github.com/vaultdrop/backend/internal/auth"
"github.com/vaultdrop/backend/internal/service"
)
@@ -17,6 +19,7 @@ type Handler struct {
}
func New(
database *sql.DB,
resourceSvc *service.ResourceService,
ocrSvc *service.OCRService,
urlSvc *service.URLService,
@@ -36,7 +39,7 @@ func New(
broker: eventBroker,
},
OCR: &OCRHandler{ocr: ocrSvc, resources: resourceSvc},
Health: &HealthHandler{ocr: ocrSvc},
Health: &HealthHandler{db: database, ocr: ocrSvc},
Auth: authHandler,
Share: &ShareHandler{rebac: rebacSvc},
Device: &DeviceHandler{placement: placementSvc},
+31 -1
View File
@@ -1,14 +1,44 @@
package handler
import (
"database/sql"
"github.com/gin-gonic/gin"
"github.com/vaultdrop/backend/pkg/api"
)
type HealthHandler struct {
db *sql.DB
ocr interface{ HealthCheck() error }
}
func (h *HealthHandler) Check(c *gin.Context) {
api.Success(c, gin.H{"status": "healthy"})
checks := gin.H{}
dbErr := h.db.Ping()
if dbErr != nil {
checks["database"] = "error: " + dbErr.Error()
} else {
checks["database"] = "ok"
}
ocrErr := h.ocr.HealthCheck()
if ocrErr != nil {
checks["ocr"] = "error: " + ocrErr.Error()
} else {
checks["ocr"] = "ok"
}
status := "healthy"
for _, v := range checks {
if v != "ok" {
status = "degraded"
break
}
}
api.Success(c, gin.H{
"status": status,
"checks": checks,
})
}
+25 -4
View File
@@ -65,11 +65,31 @@ func (h *ResourceHandler) Upload(c *gin.Context) {
api.Success(c, results)
}
func parsePagination(c *gin.Context) (page, limit int) {
page = 1
limit = 20
if p := c.Query("page"); p != "" {
if n, err := strconv.Atoi(p); err == nil && n > 0 {
page = n
}
}
if l := c.Query("limit"); l != "" {
if n, err := strconv.Atoi(l); err == nil && n > 0 {
if n > 100 {
n = 100
}
limit = n
}
}
return
}
func (h *ResourceHandler) List(c *gin.Context) {
userID := c.GetString(auth.UserIDKey)
thumbnailQuality := c.Query("thumbnail")
page, limit := parsePagination(c)
resources, err := h.resources.List(userID)
resources, total, err := h.resources.List(userID, page, limit)
if err != nil {
log.Printf("ERROR List resources: %v", err)
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to list resources")
@@ -132,7 +152,7 @@ func (h *ResourceHandler) List(c *gin.Context) {
}
}
api.Paginated(c, resp, 1, len(resp))
api.Paginated(c, resp, page, total)
}
func (h *ResourceHandler) Download(c *gin.Context) {
@@ -335,8 +355,9 @@ func (h *ResourceHandler) ListByParent(c *gin.Context) {
userID := c.GetString(auth.UserIDKey)
parentID := c.Param("id")
thumbnailQuality := c.Query("thumbnail")
page, limit := parsePagination(c)
resources, err := h.resources.ListResourcesByParentID(parentID, userID)
resources, total, err := h.resources.ListResourcesByParentID(parentID, userID, page, limit)
if err != nil {
api.Error(c, http.StatusInternalServerError, "DB_ERROR", "Failed to list resources in folder")
return
@@ -396,7 +417,7 @@ func (h *ResourceHandler) ListByParent(c *gin.Context) {
}
}
api.Success(c, resp)
api.Paginated(c, resp, page, total)
}
func (h *ResourceHandler) GetVariants(c *gin.Context) {