V3 S1-S2 : corbeille + versions + extract générique
S1 filet (backend + mobile) : corbeille 30j (deleted_at réutilisé, trash/restore récursifs, purge auto serveur), versions N=3 à chaque overwrite, ops outbox trash/restore/purge (delete legacy mappé), Room v19 (trashed_at), Deleters -> trash, écran Corbeille, walk guards. S2 extract (backend) : package extract (règles FR stdlib, corpus testé), resource_facts 000019 (origin auto/user), hook worker OCR + backfill boot, GET /files/:id/facts (viewer+). Contrat docs/api-v1.md étendu, V3.md (vision + plan).
This commit is contained in:
+127
-2
@@ -107,7 +107,32 @@ func FilesGetOcr(c *gin.Context) {
|
||||
api.OK(c, dto)
|
||||
}
|
||||
|
||||
// FilesContent streame les octets physiques d'un fichier visible (viewer+,
|
||||
// FilesGetFacts expose les faits génériques d'un fichier visible (V3 S2) :
|
||||
// GET /files/:id/facts. Même portée que l'OCR (viewer+, own ou shared) —
|
||||
// les faits dérivent du texte. `[]` si rien d'extractible (jamais 404 pour
|
||||
// un fichier visible sans faits) ; 404 si trashé/absent/étranger.
|
||||
func FilesGetFacts(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
|
||||
}
|
||||
facts, err := Store.GetFacts(userID, id)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
if facts == nil {
|
||||
facts = []service.FactDTO{}
|
||||
}
|
||||
api.OK(c, facts)
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -145,7 +170,19 @@ func FilesDelete(c *gin.Context) {
|
||||
api.Error(c, http.StatusNotFound, "NOT_FOUND", "file not found")
|
||||
return
|
||||
}
|
||||
deletedID, err := Store.DeleteFile(userID, id)
|
||||
// V3 corbeille : DELETE = trash par défaut ; ?mode=purge = destruction
|
||||
// définitive (lignes + versions + octets). Mode inconnu → 400.
|
||||
var deletedID string
|
||||
var err error
|
||||
switch c.Query("mode") {
|
||||
case "", "trash":
|
||||
deletedID, err = Store.Trash(userID, id)
|
||||
case "purge":
|
||||
deletedID, err = Store.Purge(userID, id)
|
||||
default:
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "invalid query param `mode` (trash|purge)")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
@@ -153,6 +190,94 @@ func FilesDelete(c *gin.Context) {
|
||||
api.OK(c, gin.H{"id": deletedID})
|
||||
}
|
||||
|
||||
// FilesRestore restaure une ressource trashée (POST /files/:id/restore).
|
||||
// Absente/étrangère → 404 NOT_FOUND ; déjà vivante → succès idempotent.
|
||||
func FilesRestore(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
|
||||
}
|
||||
restoredID, err := Store.Restore(userID, id)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OK(c, gin.H{"id": restoredID})
|
||||
}
|
||||
|
||||
// TrashList expose la corbeille (GET /trash) : ressources trashées du user,
|
||||
// les plus récentes d'abord, paginé comme les autres listes.
|
||||
func TrashList(c *gin.Context) {
|
||||
if Store == nil {
|
||||
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
||||
return
|
||||
}
|
||||
userID := c.GetString(UserIDKey)
|
||||
page, pageSize, ok := parsePageParams(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
items, total, err := Store.ListTrashed(userID, page, pageSize)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OKList(c, items, page, pageSize, total)
|
||||
}
|
||||
|
||||
// VersionsList expose l'historique des octets (GET /files/:id/versions),
|
||||
// le plus récent d'abord. Ressource trashée/absente/étrangère → 404.
|
||||
func VersionsList(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
|
||||
}
|
||||
versions, err := Store.ListVersions(userID, id)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OK(c, versions)
|
||||
}
|
||||
|
||||
// VersionRestore recopie la génération n vers le live
|
||||
// (POST /files/:id/versions/:n/restore). Génération inconnue → 404.
|
||||
func VersionRestore(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
|
||||
}
|
||||
n, err := strconv.Atoi(c.Param("n"))
|
||||
if err != nil || n < 1 {
|
||||
api.Error(c, http.StatusNotFound, "NOT_FOUND", "version not found")
|
||||
return
|
||||
}
|
||||
dto, err := Store.RestoreVersion(userID, id, n)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OK(c, dto)
|
||||
}
|
||||
|
||||
func FilesUpload(c *gin.Context) {
|
||||
if Store == nil {
|
||||
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
||||
|
||||
Reference in New Issue
Block a user