Files
iu 50dff63ece feat: rename service to galo, add halo branding and release build
- rename Go module, binary, systemd unit, PG_DATABASE default, frontend package and docs from shared-album to galo
- add theme-aware halo emblem and favicon (new ui-branding capability)
- add make build-release (versioned, stripped, static binary) and run the binary from the repo root
2026-10-11 11:36:56 +03:00

59 lines
1.3 KiB
Go

package sharelinks
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"galo/internal/auth"
"galo/internal/httpx"
)
type Handler struct {
svc *Service
}
func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} }
type createRequest struct {
ExpiresIn string `json:"expires_in"`
}
func (h *Handler) Create(c *gin.Context) {
var req createRequest
_ = c.ShouldBindJSON(&req)
var ttl time.Duration
if req.ExpiresIn != "" {
d, err := time.ParseDuration(req.ExpiresIn)
if err != nil {
httpx.RespondError(c, httpx.BadRequest("invalid_expires_in", "invalid expires_in duration"))
return
}
ttl = d
}
link, err := h.svc.Create(c.Request.Context(), c.Param("id"), auth.UserID(c), ttl)
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusCreated, gin.H{"share_link": link})
}
func (h *Handler) List(c *gin.Context) {
list, err := h.svc.List(c.Request.Context(), c.Param("id"), auth.UserID(c))
if err != nil {
httpx.RespondError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"share_links": list})
}
func (h *Handler) Revoke(c *gin.Context) {
if err := h.svc.Revoke(c.Request.Context(), c.Param("id"), c.Param("link_id"), auth.UserID(c)); err != nil {
httpx.RespondError(c, err)
return
}
c.Status(http.StatusNoContent)
}