V3 S5 : graphe documentaire + doublons + collections

Backend : resource_links + scan_session_id (000021), réconciliation
déterministe (same_scan outbox, doublons SHA-256 à l'upload + backfill,
same_issuer/référence via faits effectifs, verdicts préservés, élagage
auto), GET /files/:id/relations + verdict (owner-only),
GET /duplicates (groupes + gain récupérable). Tests service + handlers
+ migrations.

Mobile (Room v22) : links + collections, scanSessionId dans les creates
de scan, LinksRepository (sync + verdicts REST), « Voir aussi » dans la
fiche (verdict infirmer/re-confirmer), écran Doublons (garder le plus
récent), collections locales (sauver/rejouer/supprimer). FR/EN.

Contrat docs/api-v1.md (/relations, pas /links — pris par le partage),
V3.md (S5 livré, version_of non matérialisé).
This commit is contained in:
venture
2026-09-26 11:16:35 +02:00
parent 2d984fd665
commit 37dc36f1f2
66 changed files with 3933 additions and 34 deletions
+19 -4
View File
@@ -34,7 +34,9 @@ type FactDTO struct {
// ProcessText extracts facts from text and replaces the resource's auto
// facts. Empty text clears stale auto facts. Never touches user corrections.
func (e *Extract) ProcessText(resourceID, text string) error {
// Afterwards the deterministic links are reconciled (same_issuer /
// same_reference may have appeared or vanished) — best-effort.
func (e *Extract) ProcessText(ownerID, resourceID, text string) error {
raw := extract.FromText(text)
params := make([]repository.FactParam, 0, len(raw))
for _, f := range raw {
@@ -59,7 +61,13 @@ func (e *Extract) ProcessText(resourceID, text string) error {
Confidence: f.Confidence,
})
}
return e.Repository.Resources.UpsertAutoFacts(resourceID, params)
if err := e.Repository.Resources.UpsertAutoFacts(resourceID, params); err != nil {
return err
}
if err := e.Repository.Resources.ReconcileLinks(ownerID, resourceID); err != nil {
log.Printf("extract: reconcile %s: %v", resourceID, err)
}
return nil
}
// Backfill processes files with OCR text but no auto facts yet (one boot
@@ -75,7 +83,7 @@ func (e *Extract) Backfill(batch int) (int, error) {
return total, nil
}
for _, p := range pending {
if err := e.ProcessText(p.ResourceID, p.Text); err != nil {
if err := e.ProcessText(p.UserID, p.ResourceID, p.Text); err != nil {
log.Printf("extract: backfill %s: %v", p.ResourceID, err)
continue
}
@@ -140,7 +148,14 @@ func (s *Resources) CorrectFacts(userID, resourceID string, facts []FactDTO) err
}
params = append(params, p)
}
return s.Repository.Resources.CorrectFacts(resourceID, params)
if err := s.Repository.Resources.CorrectFacts(resourceID, params); err != nil {
return err
}
// Les faits ont changé : les arêtes same_issuer/same_reference suivent.
if err := s.Repository.Resources.ReconcileLinks(userID, resourceID); err != nil {
log.Printf("extract: reconcile %s: %v", resourceID, err)
}
return nil
}
func validateFactParam(i int, f FactDTO) (repository.FactParam, error) {
+8 -8
View File
@@ -27,7 +27,7 @@ func TestProcessTextPersistsAutoFacts(t *testing.T) {
t.Fatalf("insert: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
facts, err := s.GetFacts(userID, fileID)
@@ -74,11 +74,11 @@ func TestProcessTextPreservesUserCorrections(t *testing.T) {
t.Fatalf("seed user fact: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
// Re-passe (idempotence du remplacement auto).
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("re-process: %v", err)
}
facts, err := s.GetFacts(userID, fileID)
@@ -122,10 +122,10 @@ func TestProcessTextEmptyClearsStaleAuto(t *testing.T) {
if err := s.Repository.Resources.InsertFile(userID, fileID, "doc.pdf", "", 0, nil, nil); err != nil {
t.Fatalf("insert: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
if err := ex.ProcessText(fileID, ""); err != nil {
if err := ex.ProcessText(userID, fileID, ""); err != nil {
t.Fatalf("clear: %v", err)
}
facts, err := s.GetFacts(userID, fileID)
@@ -145,7 +145,7 @@ func TestGetFactsScope(t *testing.T) {
if err := s.Repository.Resources.InsertFile(owner, fileID, "doc.pdf", "", 0, nil, nil); err != nil {
t.Fatalf("insert: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(owner, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
@@ -207,7 +207,7 @@ func TestCorrectFactsReplacesUserSet(t *testing.T) {
if err := s.Repository.Resources.InsertFile(userID, fileID, "facture.pdf", "", 0, nil, nil); err != nil {
t.Fatalf("insert: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
@@ -311,7 +311,7 @@ func TestSyncOpCorrectFacts(t *testing.T) {
if err := s.Repository.Resources.InsertFile(userID, fileID, "facture.pdf", "", 0, nil, nil); err != nil {
t.Fatalf("insert: %v", err)
}
if err := ex.ProcessText(fileID, extractCorpus); err != nil {
if err := ex.ProcessText(userID, fileID, extractCorpus); err != nil {
t.Fatalf("process: %v", err)
}
foreignID := repository.NewID()
+218
View File
@@ -0,0 +1,218 @@
package service
import (
"crypto/sha256"
"encoding/hex"
"errors"
"io"
"log"
"os"
"path/filepath"
"strings"
"github.com/kazier/backend/repository"
)
// RelationDTO serializes one edge of GET /files/:id/relations (V3 S5).
type RelationDTO struct {
ID string `json:"id"`
OtherID string `json:"otherId"`
Type string `json:"type"`
Confidence float64 `json:"confidence"`
CreatedBy string `json:"createdBy"`
OtherName string `json:"otherName"`
OtherType string `json:"otherType"`
OtherSize int64 `json:"otherSize"`
}
// validLinkTypes mirrors the resource_links CHECK (migration 000021).
var validLinkTypes = map[string]bool{
repository.LinkSameScan: true,
repository.LinkDuplicateOf: true,
repository.LinkSameIssuer: true,
repository.LinkSameReference: true,
}
// ListRelations reconciles then returns the live edges of an owned resource
// (owner-only : shared docs don't expose the owner's graph, S5 scope).
func (s *Resources) ListRelations(ownerID, resourceID string) ([]RelationDTO, error) {
owned, err := s.Repo.ExistsOwner(ownerID, resourceID)
if err != nil {
return nil, err
}
if !owned {
return nil, repository.ErrNotFound
}
if err := s.Repo.ReconcileLinks(ownerID, resourceID); err != nil {
return nil, err
}
rows, err := s.Repo.ListLinks(resourceID)
if err != nil {
return nil, err
}
out := make([]RelationDTO, 0, len(rows))
for _, row := range rows {
out = append(out, RelationDTO{
ID: row.ID, OtherID: row.OtherID, Type: row.Type,
Confidence: row.Confidence, CreatedBy: row.CreatedBy,
OtherName: row.OtherName, OtherType: row.OtherType, OtherSize: row.OtherSize,
})
}
return out, nil
}
// LinkVerdict records an explicit verdict on an edge (owner-only, both ends
// owned-live). Confirm → 1.0, invalidate → 0.0 (kept, blocks re-creation).
func (s *Resources) LinkVerdict(ownerID, resourceID, otherID, linkType string, confirmed bool) error {
if !validLinkTypes[linkType] {
return ErrInvalidLinkType
}
if otherID == resourceID {
return ErrInvalidLinkType
}
for _, id := range []string{resourceID, otherID} {
owned, err := s.Repo.ExistsOwner(ownerID, id)
if err != nil {
return err
}
if !owned {
return repository.ErrNotFound
}
}
return s.Repo.SetUserVerdict(resourceID, otherID, linkType, confirmed)
}
// DuplicateGroupDTO serializes one set of byte-identical files (B2).
type DuplicateGroupDTO struct {
ContentHash string `json:"contentHash"`
Count int `json:"count"`
TotalBytes int64 `json:"totalBytes"`
ReclaimableBytes int64 `json:"reclaimableBytes"`
Files []DuplicateFileDTO `json:"files"`
}
// DuplicateFileDTO serializes one member (newest first).
type DuplicateFileDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
UpdatedAt int64 `json:"updatedAt"`
}
// ListDuplicates returns the owner's byte-identical file sets, biggest
// first. Owner scope (own files only) — `[]` when clean.
func (s *Resources) ListDuplicates(ownerID string) ([]DuplicateGroupDTO, error) {
groups, err := s.Repo.ListDuplicateGroups(ownerID)
if err != nil {
return nil, err
}
out := make([]DuplicateGroupDTO, 0, len(groups))
for _, g := range groups {
dto := DuplicateGroupDTO{
ContentHash: g.ContentHash, Count: g.Count,
TotalBytes: g.TotalBytes, ReclaimableBytes: g.ReclaimableBytes,
Files: make([]DuplicateFileDTO, 0, len(g.Files)),
}
for _, f := range g.Files {
dto.Files = append(dto.Files, DuplicateFileDTO{
ID: f.ID, Name: f.Name, Size: f.Size, UpdatedAt: f.UpdatedAt,
})
}
out = append(out, dto)
}
return out, nil
}
// ErrInvalidLinkType marks client verdict-validation failures (400).
var ErrInvalidLinkType = errors.New("invalid link type or pair")
// hashPhysical computes the SHA-256 of the live bytes (safe resolution,
// same pattern as OpenContent). Absent → ErrNotFound.
func (s *Resources) hashPhysical(ownerID, resourceID string) (string, error) {
if !idPattern.MatchString(ownerID) || !idPattern.MatchString(resourceID) {
return "", repository.ErrNotFound
}
base, err := filepath.EvalSymlinks(s.UploadDir)
if err != nil {
return "", err
}
matches, err := filepath.Glob(filepath.Join(s.UploadDir, ownerID, resourceID+".*"))
if err != nil {
return "", err
}
for _, m := range matches {
if !strings.HasPrefix(filepath.Base(m), resourceID+".") {
continue
}
fi, err := os.Lstat(m)
if err != nil || !fi.Mode().IsRegular() {
continue
}
resolved, err := filepath.EvalSymlinks(m)
if err != nil {
continue
}
rel, err := filepath.Rel(base, resolved)
if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
continue
}
f, err := os.Open(resolved)
if err != nil {
return "", err
}
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
f.Close()
return "", err
}
f.Close()
return hex.EncodeToString(h.Sum(nil)), nil
}
return "", repository.ErrNotFound
}
// refreshContentHash (re)computes and stores the hash after bytes arrive.
// Best-effort : un échec ne fait jamais échouer l'upload (loggé).
func (s *Resources) refreshContentHash(ownerID, resourceID string) {
hash, err := s.hashPhysical(ownerID, resourceID)
if err != nil {
return
}
if err := s.Repo.SetContentHash(ownerID, resourceID, hash); err != nil {
log.Printf("content: SetContentHash(%s): %v", resourceID, err)
return
}
// Des octets identiques à une autre ressource = doublon à relier.
if err := s.Repo.ReconcileLinks(ownerID, resourceID); err != nil {
log.Printf("content: reconcile(%s): %v", resourceID, err)
}
}
// BackfillHashes hashes live files missing content_hash (bounded batches,
// boot pass — uploads d'avant la V3). Returns files hashed.
func (s *Resources) BackfillHashes(batch int) (int, error) {
total := 0
for {
pending, err := s.Repo.ListMissingHashes(batch)
if err != nil {
return total, err
}
if len(pending) == 0 {
return total, nil
}
for _, p := range pending {
hash, err := s.hashPhysical(p.UserID, p.ResourceID)
if err != nil {
continue // metadata-only : rien à hasher, re-tenté au prochain upload.
}
if err := s.Repo.SetContentHash(p.UserID, p.ResourceID, hash); err != nil {
log.Printf("content: backfill hash %s: %v", p.ResourceID, err)
continue
}
if err := s.Repo.ReconcileLinks(p.UserID, p.ResourceID); err != nil {
log.Printf("content: backfill reconcile %s: %v", p.ResourceID, err)
}
total++
}
}
}
+252
View File
@@ -0,0 +1,252 @@
package service
import (
"errors"
"testing"
"github.com/kazier/backend/repository"
)
func mustLinkFile(t *testing.T, s *Resources, userID, name string) string {
t.Helper()
id := repository.NewID()
if err := s.Repository.Resources.InsertFile(userID, id, name, "", 0, nil, nil); err != nil {
t.Fatalf("insert %q: %v", name, err)
}
return id
}
func relationTypes(rels []RelationDTO) map[string]int {
out := map[string]int{}
for _, r := range rels {
out[r.Type]++
}
return out
}
func TestSameScanViaOutbox(t *testing.T) {
s := newServiceStore(t)
userID := mustCreateUser(t, s.Repository, "links-scan")
device := mustRegisterDevice(t, s.Repository, "d0000000000000000000000000000001")
session := repository.NewID()
page1 := repository.NewID()
page2 := repository.NewID()
create := func(opID, resID, name string) {
t.Helper()
res, err := s.ApplyBatch(userID, device, []SyncOperation{
syncOp(opID, resID, OpCreateResource, "file", map[string]any{
"name": resID + "-" + name, "scanSessionId": session,
}),
})
if err != nil {
t.Fatalf("apply: %v", err)
}
if res.Applied != 1 || res.Failed != nil {
t.Fatalf("create %s: %+v", name, res)
}
}
create(repository.NewID(), page1, "p1.png")
create(repository.NewID(), page2, "p2.png")
rels, err := s.ListRelations(userID, page1)
if err != nil {
t.Fatalf("relations: %v", err)
}
if relationTypes(rels)[repository.LinkSameScan] != 1 || rels[0].OtherID != page2 {
t.Fatalf("same_scan manquant: %+v", rels)
}
if rels[0].Confidence != 1.0 || rels[0].CreatedBy != "auto" {
t.Fatalf("arête same_scan inattendue: %+v", rels[0])
}
// Session invalide → halt INVALID_REQUEST (pas d'écriture partielle).
res, err := s.ApplyBatch(userID, device, []SyncOperation{
syncOp(repository.NewID(), repository.NewID(), OpCreateResource, "file", map[string]any{
"name": "bad.png", "scanSessionId": "nope",
}),
})
if err != nil {
t.Fatalf("apply: %v", err)
}
if res.Failed == nil || res.Failed.Code != "INVALID_REQUEST" {
t.Fatalf("session invalide doit halter: %+v", res)
}
}
func TestDuplicateOfViaUploadHash(t *testing.T) {
s := newServiceStore(t)
userID := mustCreateUser(t, s.Repository, "links-dupe")
a, err := s.Upload(userID, multipartFileHeader(t, "a.txt", []byte("meme-contenu")), "", "")
if err != nil {
t.Fatalf("upload a: %v", err)
}
b, err := s.Upload(userID, multipartFileHeader(t, "b.txt", []byte("meme-contenu")), "", "")
if err != nil {
t.Fatalf("upload b: %v", err)
}
rels, err := s.ListRelations(userID, a.ID)
if err != nil {
t.Fatalf("relations: %v", err)
}
if relationTypes(rels)[repository.LinkDuplicateOf] != 1 || rels[0].OtherID != b.ID {
t.Fatalf("duplicate_of manquant: %+v", rels)
}
// Contenu différent → pas de doublon.
c, err := s.Upload(userID, multipartFileHeader(t, "c.txt", []byte("autre-contenu")), "", "")
if err != nil {
t.Fatalf("upload c: %v", err)
}
relsC, err := s.ListRelations(userID, c.ID)
if err != nil {
t.Fatalf("relations c: %v", err)
}
if len(relsC) != 0 {
t.Fatalf("faux doublon: %+v", relsC)
}
}
func TestSameIssuerViaFacts(t *testing.T) {
s, ex := newExtractStore(t)
userID := mustCreateUser(t, s.Repository, "links-issuer")
f1 := mustLinkFile(t, s, userID, "f1.pdf")
f2 := mustLinkFile(t, s, userID, "f2.pdf")
if err := ex.ProcessText(userID, f1, "EDF\nFacture 10,00 €\n"); err != nil {
t.Fatalf("extract f1: %v", err)
}
if err := ex.ProcessText(userID, f2, "EDF\nFacture 20,00 €\n"); err != nil {
t.Fatalf("extract f2: %v", err)
}
rels, err := s.ListRelations(userID, f1)
if err != nil {
t.Fatalf("relations: %v", err)
}
if relationTypes(rels)[repository.LinkSameIssuer] != 1 {
t.Fatalf("same_issuer manquant: %+v", rels)
}
// Correction de l'émetteur → l'arête disparaît (prune auto).
if err := s.CorrectFacts(userID, f2, []FactDTO{{FactType: "issuer", ValueText: "ENGIE", Confidence: 1}}); err != nil {
t.Fatalf("correct: %v", err)
}
rels, err = s.ListRelations(userID, f1)
if err != nil {
t.Fatalf("relations 2: %v", err)
}
if relationTypes(rels)[repository.LinkSameIssuer] != 0 {
t.Fatalf("arête périmée non élaguée: %+v", rels)
}
}
func TestLinkVerdict(t *testing.T) {
s := newServiceStore(t)
userID := mustCreateUser(t, s.Repository, "links-verdict")
other := mustCreateUser(t, s.Repository, "links-verdict-x")
device := mustRegisterDevice(t, s.Repository, "d0000000000000000000000000000002")
session := repository.NewID()
p1, p2 := repository.NewID(), repository.NewID()
for _, id := range []string{p1, p2} {
res, err := s.ApplyBatch(userID, device, []SyncOperation{
syncOp(repository.NewID(), id, OpCreateResource, "file", map[string]any{
"name": id, "scanSessionId": session,
}),
})
if err != nil || res.Applied != 1 || res.Failed != nil {
t.Fatalf("create %s: %+v %v", id, res, err)
}
}
// Invalider : l'arête reste (confiance 0, verdict user) mais ne bloque rien.
if err := s.LinkVerdict(userID, p1, p2, repository.LinkSameScan, false); err != nil {
t.Fatalf("verdict: %v", err)
}
rels, _ := s.ListRelations(userID, p1)
if len(rels) != 1 || rels[0].Confidence != 0 || rels[0].CreatedBy != "user" {
t.Fatalf("verdict infirme inattendu: %+v", rels)
}
// Re-reconcile ne ressuscite pas l'arête invalidée.
rels, _ = s.ListRelations(userID, p1)
if len(rels) != 1 || rels[0].Confidence != 0 {
t.Fatalf("arête invalidée ressuscitée: %+v", rels)
}
// Re-confirmer : retour à 1.0 user.
if err := s.LinkVerdict(userID, p1, p2, repository.LinkSameScan, true); err != nil {
t.Fatalf("re-verdict: %v", err)
}
rels, _ = s.ListRelations(userID, p1)
if len(rels) != 1 || rels[0].Confidence != 1.0 || rels[0].CreatedBy != "user" {
t.Fatalf("re-verdict inattendu: %+v", rels)
}
// Type inconnu → erreur 400-candidate ; paire réflexive idem.
if err := s.LinkVerdict(userID, p1, p2, "copains", true); !errors.Is(err, ErrInvalidLinkType) {
t.Fatalf("type inconnu : attendu ErrInvalidLinkType, got %v", err)
}
if err := s.LinkVerdict(userID, p1, p1, repository.LinkSameScan, true); !errors.Is(err, ErrInvalidLinkType) {
t.Fatalf("paire réflexive : attendu ErrInvalidLinkType, got %v", err)
}
// Autrui → NOT_FOUND (pas d'oracle).
foreign := mustLinkFile(t, s, other, "x.pdf")
if err := s.LinkVerdict(other, foreign, p1, repository.LinkSameScan, true); err != repository.ErrNotFound {
t.Fatalf("verdict trans-compte : attendu NOT_FOUND, got %v", err)
}
if _, err := s.ListRelations(other, p1); err != repository.ErrNotFound {
t.Fatalf("lecture trans-compte : attendu NOT_FOUND, got %v", err)
}
}
func TestListDuplicates(t *testing.T) {
s := newServiceStore(t)
userID := mustCreateUser(t, s.Repository, "links-dupes")
other := mustCreateUser(t, s.Repository, "links-dupes-x")
a, err := s.Upload(userID, multipartFileHeader(t, "a.txt", []byte("doublon")), "", "")
if err != nil {
t.Fatalf("upload a: %v", err)
}
b, err := s.Upload(userID, multipartFileHeader(t, "b.txt", []byte("doublon")), "", "")
if err != nil {
t.Fatalf("upload b: %v", err)
}
if _, err := s.Upload(userID, multipartFileHeader(t, "c.txt", []byte("unique-contenu")), "", ""); err != nil {
t.Fatalf("upload c: %v", err)
}
// Même contenu chez un autre compte : pas mon doublon.
if _, err := s.Upload(other, multipartFileHeader(t, "z.txt", []byte("doublon")), "", ""); err != nil {
t.Fatalf("upload other: %v", err)
}
groups, err := s.ListDuplicates(userID)
if err != nil {
t.Fatalf("duplicates: %v", err)
}
if len(groups) != 1 || groups[0].Count != 2 {
t.Fatalf("groupes inattendus: %+v", groups)
}
g := groups[0]
if g.TotalBytes != 14 || g.ReclaimableBytes != 7 {
t.Fatalf("tailles inattendues: %+v", g)
}
ids := map[string]bool{}
for _, f := range g.Files {
ids[f.ID] = true
}
if !ids[a.ID] || !ids[b.ID] {
t.Fatalf("membres inattendus: %+v", g.Files)
}
// Compte propre → [] (jamais null).
empty, err := s.ListDuplicates(other)
if err != nil {
t.Fatalf("duplicates other: %v", err)
}
if len(empty) != 0 {
t.Fatalf("compte sans doublon: %+v", empty)
}
}
+3
View File
@@ -412,6 +412,9 @@ func (s *Resources) Upload(ownerID string, file *multipart.FileHeader, folderID,
}
return FileDTO{}, err
}
// V3 S5 : octets frais → hash (doublons) + réconciliation des liens.
// Best-effort (jamais d'échec sur du hashing).
s.refreshContentHash(ownerID, resourceID)
return toFileDTO(row), nil
}
+17
View File
@@ -64,6 +64,9 @@ type createResourcePayload struct {
ParentResourceID string `json:"parentResourceId"` // dossier parent (racine si vide), cf. docs/api-v1.md §6.1
MimeType string `json:"mimeType"`
Extension string `json:"extension"`
// V3 S5 : session de scan opaque (32-hex mobile) — le serveur en déduit
// les arêtes same_scan. Absent = ressource isolée (jamais d'erreur).
ScanSessionID string `json:"scanSessionId"`
}
type renamePayload struct {
@@ -241,6 +244,11 @@ func (s *Resources) applySyncOp(ownerID, deviceID string, op *SyncOperation) err
if p.Name == "" {
return errors.New("payload.name required")
}
// V3 S5 : session de scan opaque (dérive same_scan, jamais d'erreur
// bloquante au-delà du format).
if p.ScanSessionID != "" && !resourceIDPattern.MatchString(p.ScanSessionID) {
return errors.New("payload.scanSessionId must be 32 lowercase hex chars")
}
// Le parent doit exister et appartenir à l'utilisateur (NOT_FOUND sinon,
// cohérent avec move_resource). Ordre du SAF walk : parent avant enfant.
if p.ParentResourceID != "" {
@@ -270,6 +278,15 @@ func (s *Resources) applySyncOp(ownerID, deviceID string, op *SyncOperation) err
}
return insertErr
}
// V3 S5 : session de scan → arêtes same_scan (best-effort, jamais
// bloquant : la ressource existe, seuls les liens manqueraient).
if p.ScanSessionID != "" {
if err := s.Repo.SetScanSession(ownerID, resourceID, p.ScanSessionID); err != nil {
log.Printf("sync: scan session %s: %v", resourceID, err)
} else if err := s.Repo.ReconcileLinks(ownerID, resourceID); err != nil {
log.Printf("sync: reconcile %s: %v", resourceID, err)
}
}
return nil
case OpUpdateMetadata: