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
+90
View File
@@ -183,6 +183,96 @@ func FilesCorrectFacts(c *gin.Context) {
api.OK(c, facts)
}
// RelationsList expose le graphe documentaire d'une ressource possédée
// (V3 S5) : `GET /files/:id/relations`. Réconcilie d'abord (les arêtes
// déterministes convergent à la lecture), puis renvoie les arêtes vivantes
// (l'autre bout non trashé), confiance décroissante. Owner-only : le graphe
// d'autrui ne s'énumère pas (404, comme `/shares`).
func RelationsList(c *gin.Context) {
if Store == nil {
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
return
}
userID := c.GetString(UserIDKey)
id := c.Param("id")
if !deviceIDPattern.MatchString(id) {
api.Error(c, http.StatusNotFound, "NOT_FOUND", "file not found")
return
}
relations, err := Store.ListRelations(userID, id)
if err != nil {
writeError(c, err)
return
}
if relations == nil {
relations = []service.RelationDTO{}
}
api.OK(c, relations)
}
// RelationVerdict enregistre un verdict explicite sur une arête (V3 S5) :
// `POST /files/:id/relations/verdict { otherId, linkType, confirmed }`.
// Confirmé → 1.0, infirmé → 0.0 (conservé, bloque la re-création auto).
// Owner-only, les deux bouts possédés et vifs, sinon 404 ; type/paire
// invalide → 400.
func RelationVerdict(c *gin.Context) {
if Store == nil {
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
return
}
userID := c.GetString(UserIDKey)
id := c.Param("id")
if !deviceIDPattern.MatchString(id) {
api.Error(c, http.StatusNotFound, "NOT_FOUND", "file not found")
return
}
var req struct {
OtherID string `json:"otherId"`
LinkType string `json:"linkType"`
Confirmed bool `json:"confirmed"`
}
if err := c.ShouldBindJSON(&req); err != nil {
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "invalid JSON body (expected { otherId, linkType, confirmed })")
return
}
if !deviceIDPattern.MatchString(req.OtherID) {
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "invalid `otherId` (32 lowercase hex)")
return
}
if err := Store.LinkVerdict(userID, id, req.OtherID, req.LinkType, req.Confirmed); err != nil {
if errors.Is(err, service.ErrInvalidLinkType) {
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", err.Error())
return
}
writeError(c, err)
return
}
relations, err := Store.ListRelations(userID, id)
if err != nil {
writeError(c, err)
return
}
api.OK(c, relations)
}
// DuplicatesList expose les doublons d'octets du compte (V3 S5 B2) :
// `GET /duplicates`. Groupes par hash, plus gros d'abord, avec le gain
// récupérable (« garder un seul »). Scope owner — `[]` quand propre.
func DuplicatesList(c *gin.Context) {
if Store == nil {
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
return
}
userID := c.GetString(UserIDKey)
groups, err := Store.ListDuplicates(userID)
if err != nil {
writeError(c, err)
return
}
api.OK(c, groups)
}
// FilesContent streame les octets physiques d'un fichier visible (viewer+,
// own ou shared) : GET /files/:id/content. Réponse binaire (Content-Type du
// fichier, Content-Disposition inline) — jamais d'enveloppe {data}. Supporte
// Range via http.ServeContent (Gin c.File). Sans bytes serveur (ressource