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:
@@ -18,6 +18,10 @@ import (
|
||||
// ErrFileTooLarge signals an upload above MaxFileSize.
|
||||
var ErrFileTooLarge = errors.New("file too large")
|
||||
|
||||
// ErrQuotaExceeded signals an upload that would overflow the account quota
|
||||
// (V3 S6 A2). Handlers map it to 413 QUOTA_EXCEEDED (never 500).
|
||||
var ErrQuotaExceeded = errors.New("storage quota exceeded")
|
||||
|
||||
// ErrInvalidUpload signals a rejected upload (display name or path component).
|
||||
// Handlers map it to 400 INVALID_REQUEST (never 500).
|
||||
var ErrInvalidUpload = errors.New("invalid upload name")
|
||||
@@ -343,6 +347,14 @@ func (s *Resources) Upload(ownerID string, file *multipart.FileHeader, folderID,
|
||||
if ferr != nil {
|
||||
return FileDTO{}, ferr
|
||||
}
|
||||
} else {
|
||||
// V3 S6 A2 : garde-fou quota sur les créations (les overwrites
|
||||
// ciblées remplacent des octets existants — gain net ~nul, pas de
|
||||
// check). Vérifié au header (rejet rapide) PUIS aux octets réels
|
||||
// (vérité, le header peut mentir, cf. A2).
|
||||
if err := s.checkQuotaFor(ownerID, file.Size); err != nil {
|
||||
return FileDTO{}, err
|
||||
}
|
||||
}
|
||||
|
||||
written, err := copyMultipartAtomic(file, destDir, destPath, s.MaxFileSize)
|
||||
@@ -352,6 +364,14 @@ func (s *Resources) Upload(ownerID string, file *multipart.FileHeader, folderID,
|
||||
}
|
||||
return FileDTO{}, err
|
||||
}
|
||||
if !targetExisting {
|
||||
// Vérité aux octets réels (le header `file.Size` peut mentir) :
|
||||
// dépassement → fichier supprimé + 413 (pas d'orphelin).
|
||||
if err := s.checkQuotaFor(ownerID, written); err != nil {
|
||||
_ = os.Remove(destPath)
|
||||
return FileDTO{}, err
|
||||
}
|
||||
}
|
||||
|
||||
mimeType := sanitizeMimeType(file.Header.Get("Content-Type"))
|
||||
var extPtr *string
|
||||
@@ -486,3 +506,48 @@ func toFileDTO(row repository.FileRow) FileDTO {
|
||||
UpdatedAt: row.UpdatedAt.UTC().Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
// UsageDTO serializes GET /users/me/usage (V3 S6 A2) : quota + empreinte,
|
||||
// dont la corbeille (octets récupérables à la purge).
|
||||
type UsageDTO struct {
|
||||
UsedBytes int64 `json:"usedBytes"`
|
||||
QuotaBytes int64 `json:"quotaBytes"`
|
||||
FileCount int `json:"fileCount"`
|
||||
TrashCount int `json:"trashCount"`
|
||||
TrashedBytes int64 `json:"trashedBytes"`
|
||||
}
|
||||
|
||||
// Usage returns the account footprint (computed, never stored).
|
||||
func (s *Resources) Usage(ownerID string) (UsageDTO, error) {
|
||||
user, err := s.Repository.Users.GetByID(ownerID)
|
||||
if err != nil {
|
||||
return UsageDTO{}, err
|
||||
}
|
||||
usage, err := s.Repo.StorageUsage(ownerID)
|
||||
if err != nil {
|
||||
return UsageDTO{}, err
|
||||
}
|
||||
return UsageDTO{
|
||||
UsedBytes: usage.UsedBytes, QuotaBytes: user.QuotaBytes,
|
||||
FileCount: usage.FileCount, TrashCount: usage.TrashCount,
|
||||
TrashedBytes: usage.TrashedBytes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// checkQuotaFor rejects a creation of incoming bytes that would overflow the
|
||||
// account quota (V3 S6 A2). Compte absent → l'erreur remonte (jamais de
|
||||
// défaut silencieux qui laisserait passer).
|
||||
func (s *Resources) checkQuotaFor(ownerID string, incoming int64) error {
|
||||
user, err := s.Repository.Users.GetByID(ownerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usage, err := s.Repo.StorageUsage(ownerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if usage.UsedBytes+incoming > user.QuotaBytes {
|
||||
return ErrQuotaExceeded
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user