CI / lint-backend (push) Failing after 1m39s
CI / lint-mobile (push) Canceled after 11m8s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/kazier/backend/pkg/api"
|
|
"github.com/kazier/backend/repository"
|
|
)
|
|
|
|
// ShareLinkGet resolves a public share link without authentication
|
|
// (GET /shares/links/:token). Returns resource metadata only — never the
|
|
// owner's identity beyond what the contract exposes.
|
|
func ShareLinkGet(c *gin.Context) {
|
|
if Store == nil || Store.Repository == nil {
|
|
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
|
return
|
|
}
|
|
token := c.Param("token")
|
|
// Contrat V1 : les tokens de lien sont du 32-hex (cf. docs/api-v1.md).
|
|
// Malformé → 400 INVALID_REQUEST (pas 404 : ce n'est pas « introuvable »,
|
|
// c'est « requête invalide »). deviceIDPattern (devices.go, même package)
|
|
// exprime exactement ce format.
|
|
if !deviceIDPattern.MatchString(token) {
|
|
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "malformed link token")
|
|
return
|
|
}
|
|
link, err := Store.Repository.Shares.GetPublicLink(token)
|
|
if err != nil {
|
|
// A6 : errors.Is (pas ==) — le repo peut envelopper ErrNotFound.
|
|
if errors.Is(err, repository.ErrNotFound) {
|
|
api.Error(c, http.StatusNotFound, "NOT_FOUND", "link not found or revoked")
|
|
return
|
|
}
|
|
api.Error(c, http.StatusInternalServerError, "INTERNAL", "could not resolve link")
|
|
return
|
|
}
|
|
api.OK(c, link)
|
|
}
|