V3 S6 : confiance (révocation, quota, appareils, conflits) + import + onboarding

Backend : token_version (000022, claim tv, 401 si révoqué, bump au
password — fin limite V1), quota (000023 idempotente, colonne héritée
de 000001, 413 QUOTA_EXCEEDED, GET /users/me/usage), devices
(GET + DELETE révocation, EnforceDeviceExists en prod), renames
concurrents transparents (baseUpdatedAt + conflicts[] non-fataux,
tolérance 2 s). Tests service + handlers + migrations + auth.

Mobile : pipeline conflits (DTO + SyncConflictStore + worker + dialogue),
baseUpdatedAt prêt, liens 7j par défaut, écran Appareils (+ quota),
import classeur unifié (scan/note/dossier), onboarding cercle Famille.

Contrat docs/api-v1.md, V3.md (S6 livré).
This commit is contained in:
venture
2026-09-26 11:56:39 +02:00
parent 37dc36f1f2
commit 1e38e6e4ee
65 changed files with 1880 additions and 53 deletions
+51
View File
@@ -124,6 +124,39 @@ func (r *Resources) ListMissingHashes(limit int) ([]MissingHash, error) {
return out, rows.Err()
}
// StorageUsage aggregates a user's footprint (V3 S6 A2 — calculé, jamais
// stocké). Les trashés sont exclus (octets récupérables à la purge).
type StorageUsage struct {
UsedBytes int64
FileCount int
TrashCount int
TrashedBytes int64
}
// StorageUsage sums live file bytes + counts (live + trashed) for a user.
func (r *Resources) StorageUsage(ownerID string) (StorageUsage, error) {
var u StorageUsage
err := r.DB.QueryRow(
`SELECT COALESCE(SUM(size_bytes), 0), COUNT(*)
FROM resources
WHERE user_id = $1 AND type = 'file' AND deleted_at IS NULL`,
ownerID,
).Scan(&u.UsedBytes, &u.FileCount)
if err != nil {
return StorageUsage{}, err
}
err = r.DB.QueryRow(
`SELECT COUNT(*), COALESCE(SUM(size_bytes), 0)
FROM resources
WHERE user_id = $1 AND deleted_at IS NOT NULL`,
ownerID,
).Scan(&u.TrashCount, &u.TrashedBytes)
if err != nil {
return StorageUsage{}, err
}
return u, nil
}
type FileRow struct {
ID string
Name string
@@ -700,6 +733,24 @@ func (r *Resources) TouchResource(resourceID string) error {
return err
}
// LiveNameAndUpdatedAt returns the current name and updated_at (ms epoch) of
// a live resource, any type, unscoped — the caller (sync) has already
// verified effective access. Absent/trashed → ErrNotFound. Sert à la
// détection de conflits de rename (S6 A4 : baseUpdatedAt périmé).
func (r *Resources) LiveNameAndUpdatedAt(resourceID string) (string, int64, error) {
var name string
var ms int64
err := r.DB.QueryRow(
`SELECT name, (EXTRACT(EPOCH FROM updated_at) * 1000)::bigint
FROM resources WHERE resource_id = $1 AND deleted_at IS NULL`,
resourceID,
).Scan(&name, &ms)
if err == sql.ErrNoRows {
return "", 0, ErrNotFound
}
return name, ms, err
}
// OwnedRow is a snapshot row: resource identity + freshness.
type OwnedRow struct {
ID string