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:
@@ -51,6 +51,79 @@ func isForeignKeyViolation(err error) bool {
|
||||
return errors.As(err, &pqErr) && pqErr.Code == "23503"
|
||||
}
|
||||
|
||||
// SetContentHash stores the SHA-256 of the live bytes (V3 S5 duplicates).
|
||||
// Owner-scoped, live rows. Best-effort côté service (jamais d'erreur vers
|
||||
// le client).
|
||||
func (r *Resources) SetContentHash(ownerID, resourceID, hash string) error {
|
||||
result, err := r.DB.Exec(
|
||||
`UPDATE resources SET content_hash = NULLIF($3, ''), updated_at = NOW()
|
||||
WHERE resource_id = $1 AND user_id = $2 AND type = 'file' AND deleted_at IS NULL`,
|
||||
resourceID, ownerID, hash,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetScanSession records the opaque client scan-session of a resource
|
||||
// (V3 S5 same_scan — drift informatif, jamais autorisant). Owner-scoped.
|
||||
func (r *Resources) SetScanSession(ownerID, resourceID, sessionID string) error {
|
||||
result, err := r.DB.Exec(
|
||||
`UPDATE resources SET scan_session_id = NULLIF($3, ''), updated_at = NOW()
|
||||
WHERE resource_id = $1 AND user_id = $2 AND deleted_at IS NULL`,
|
||||
resourceID, ownerID, sessionID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MissingHash identifies a live file without content_hash (boot backfill).
|
||||
type MissingHash struct {
|
||||
UserID string
|
||||
ResourceID string
|
||||
}
|
||||
|
||||
// ListMissingHashes returns up to limit live files with bytes but no hash.
|
||||
func (r *Resources) ListMissingHashes(limit int) ([]MissingHash, error) {
|
||||
rows, err := r.DB.Query(
|
||||
`SELECT user_id, resource_id FROM resources
|
||||
WHERE type = 'file' AND deleted_at IS NULL AND user_id IS NOT NULL AND has_content = TRUE
|
||||
AND (content_hash IS NULL OR content_hash = '')
|
||||
ORDER BY updated_at ASC LIMIT $1`,
|
||||
limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []MissingHash
|
||||
for rows.Next() {
|
||||
var m MissingHash
|
||||
if err := rows.Scan(&m.UserID, &m.ResourceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
type FileRow struct {
|
||||
ID string
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user