V3 S1-S2 : corbeille + versions + extract générique

S1 filet (backend + mobile) : corbeille 30j (deleted_at réutilisé,
trash/restore récursifs, purge auto serveur), versions N=3 à chaque
overwrite, ops outbox trash/restore/purge (delete legacy mappé), Room
v19 (trashed_at), Deleters -> trash, écran Corbeille, walk guards.

S2 extract (backend) : package extract (règles FR stdlib, corpus
testé), resource_facts 000019 (origin auto/user), hook worker OCR +
backfill boot, GET /files/:id/facts (viewer+).

Contrat docs/api-v1.md étendu, V3.md (vision + plan).
This commit is contained in:
venture
2026-09-26 10:14:07 +02:00
parent a34220bf2d
commit 95b4cf79cf
75 changed files with 5220 additions and 119 deletions
+25 -1
View File
@@ -41,6 +41,11 @@ type Ocr struct {
Lang string
Engine ocr.Engine
StaleAfter time.Duration
// OnText, quand non-nil, reçoit chaque texte extrait avec succès (V3 S2 :
// le service Extract en dérive des faits génériques). Appelé dans le
// worker, jamais dans un handler ; une erreur est loggée, pas propagée
// (le job OCR reste `done` — l'extract est un enrichissement, pas un gate).
OnText func(userID, resourceID, text string)
}
func NewOcr(repo *repository.Repository, uploadDir, lang string, engine ocr.Engine) *Ocr {
@@ -166,9 +171,10 @@ func (o *Ocr) process(ctx context.Context, row repository.OcrJobRow) {
fail(err.Error())
return
}
trimmed := strings.TrimSpace(text)
// Le texte atterrit sur la ressource (updated_at bumpé) : consultable par
// tous les devices du user et les grantees via GET /files/:id/ocr.
if trimmed := strings.TrimSpace(text); trimmed != "" {
if trimmed != "" {
if err := o.Repository.Resources.UpdateOcrText(userID, row.FileID, trimmed); err != nil {
if errors.Is(err, repository.ErrNotFound) {
fail("file not readable")
@@ -178,9 +184,27 @@ func (o *Ocr) process(ctx context.Context, row repository.OcrJobRow) {
return
}
}
// V3 S2 : faits génériques (même texte vide — purge les auto périmés).
if o.OnText != nil {
// userID capturing : le user courant, pas un owner résolu plus tard.
if terr := o.safeOnText(userID, row.FileID, trimmed); terr != nil {
log.Printf("ocr: extract %s: %v", row.FileID, terr)
}
}
complete(text)
}
// safeOnText isole un hook OnText paniquant (règle défectueuse) du worker.
func (o *Ocr) safeOnText(userID, resourceID, text string) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("extract panic: %v", r)
}
}()
o.OnText(userID, resourceID, text)
return nil
}
// physicalPath résout UPLOAD_DIR/<user_id>/<resource_id>.<ext> — l'ext est
// choisi à l'upload, le fichier réel est retrouvé par préfixe. Durci (A12) :
// identifiants 32-hex uniquement (anti `..`), `Lstat` + fichier régulier