Files
Kazier/backend/handlers/store.go
T
venture 4316da578f
Release / release-apk (push) Successful in 8m58s
Release / release-docker (push) Successful in 3m47s
CI / docker (push) Successful in 7s
CI / lint-backend (push) Successful in 1m44s
CI / lint-mobile (push) Failing after 18m59s
CI / test-backend (push) Successful in 2m12s
CI / test-mobile (push) Successful in 8m50s
CI / build-backend (push) Successful in 45s
V3 S7 : preview cloud + export chiffré + release 1.2.0
Backend : resource_previews (000024), GET /files/:id/preview (JPEG
512, images pur Go, PDF page 1 via pdftoppm + poppler au Dockerfile,
cache régénéré sur changement, 404 NO_PREVIEW sinon), POST /export
{password 8+} -> zip AES-256 streamé (fichiers vifs possédés +
manifest.json avec faits, metadata-only sans octets). Deps :
alexmullins/zip, x/image directs. Tests service + handlers + migrations.

Mobile : vignettes distantes (une requête/session puis cache WebP
versionné, garde tried, icône sinon), FileThumbnail cloud-only,
export (mot de passe jamais persisté, cache + partage FileProvider),
bouton Partager ACTION_SEND. Impression papier reportée V4. FR/EN.

Contrat docs/api-v1.md, V3.md (S7 livré, V3 close), AGENTS.md,
VERSION 1.2.0 + CHANGELOG.
2026-09-26 15:08:31 +02:00

48 lines
1.7 KiB
Go

package handlers
import (
"errors"
"log"
"github.com/gin-gonic/gin"
"github.com/kazier/backend/pkg/api"
"github.com/kazier/backend/repository"
"github.com/kazier/backend/service"
)
// Store is the business layer used by handlers; set once at startup
// (cmd/server). Nil until then.
var Store *service.Resources
// Ocr queues/reads OCR jobs; set once at startup alongside Store.
var Ocr *service.Ocr
// writeError maps repository/service sentinels to contract error codes.
func writeError(c *gin.Context, err error) {
switch {
case errors.Is(err, repository.ErrNotFound):
api.Error(c, 404, "NOT_FOUND", "resource not found")
case errors.Is(err, repository.ErrGranteeNotFound):
api.Error(c, 404, "GRANTEE_NOT_FOUND", "the specified user does not exist")
case errors.Is(err, repository.ErrGroupNotFound):
api.Error(c, 404, "GROUP_NOT_FOUND", "the specified group does not exist")
case errors.Is(err, repository.ErrNameConflict):
api.Error(c, 409, "NAME_CONFLICT", "a resource with this name already exists here")
case errors.Is(err, service.ErrFileTooLarge):
api.Error(c, 413, "FILE_TOO_LARGE", "file exceeds the maximum allowed size")
case errors.Is(err, service.ErrQuotaExceeded):
api.Error(c, 413, "QUOTA_EXCEEDED", "storage quota exceeded")
case errors.Is(err, service.ErrNoPreview):
api.Error(c, 404, "NO_PREVIEW", "no preview available for this file")
default:
// Jamais de err.Error() brut au client (fuite SQL/FS/paths, cf.
// FEEDBACK #8) : message générique, détail au log serveur.
path := ""
if c.Request != nil && c.Request.URL != nil {
path = c.Request.URL.Path
}
log.Printf("internal error: path=%s err=%v", path, err)
api.Error(c, 500, "INTERNAL", "internal error")
}
}