- ocr/tesseract.go : Engine → Tesseract subprocess (OCR_LANG fra+eng) ; PDF → calque texte via ledongthuc/pdf (go.mod : nouveau dep) - repository/ocr_jobs.go : queued→processing→done/failed, scoping device, text/error NULLIFés - service/ocr.go : Create valide le fichier (GetFile), queue + goroutine de traitement ; physique résolu par glob UPLOAD_DIR/<device>/<id>.* ; fail propre (fichier illisible, erreur moteur) - handlers/ocr.go : réels (validate fileId, NOT_FOUND si job d'un autre device), fin 501 OCR - tests end-to-end : cycle queued→done (stub moteur), NOT_FOUND fichier inconnu, scoping device - smoke réel : PNG 'VAULTDROP' → job done text='VAULTDROP' (tesseract installé) - docs/AGENTS : §5 + état des routes (tout V1 réel)
32 lines
966 B
Go
32 lines
966 B
Go
package handlers
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/vaultdrop/backend/pkg/api"
|
|
"github.com/vaultdrop/backend/repository"
|
|
"github.com/vaultdrop/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.ErrNameConflict):
|
|
api.Error(c, 409, "NAME_CONFLICT", "a resource with this name already exists here")
|
|
case errors.Is(err, service.FileTooLargeError):
|
|
api.Error(c, 413, "FILE_TOO_LARGE", "file exceeds the maximum allowed size")
|
|
default:
|
|
api.Error(c, 500, "INTERNAL", err.Error())
|
|
}
|
|
}
|