V2 : flag serveur has_content (migration 000014, lazy healing, FileDto)
This commit is contained in:
@@ -52,14 +52,15 @@ func isForeignKeyViolation(err error) bool {
|
||||
}
|
||||
|
||||
type FileRow struct {
|
||||
ID string
|
||||
Name string
|
||||
Size int64
|
||||
MimeType string
|
||||
FolderID string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
OcrText string
|
||||
ID string
|
||||
Name string
|
||||
Size int64
|
||||
MimeType string
|
||||
FolderID string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
OcrText string
|
||||
HasContent bool
|
||||
}
|
||||
|
||||
type FolderRow struct {
|
||||
@@ -172,11 +173,11 @@ func (r *Resources) InsertFolder(ownerID, id, name, parentResourceID string) err
|
||||
return r.insert(ownerID, id, name, parentResourceID, "folder", 0, nil, nil)
|
||||
}
|
||||
|
||||
const fileColumns = `resource_id, name, size_bytes, COALESCE(mime_type, ''), COALESCE(parent_id, ''), created_at, updated_at, COALESCE(ocr_text, '')`
|
||||
const fileColumns = `resource_id, name, size_bytes, COALESCE(mime_type, ''), COALESCE(parent_id, ''), created_at, updated_at, COALESCE(ocr_text, ''), COALESCE(has_content, FALSE)`
|
||||
|
||||
func (r *Resources) scanFile(scan func(...any) error) (FileRow, error) {
|
||||
var row FileRow
|
||||
err := scan(&row.ID, &row.Name, &row.Size, &row.MimeType, &row.FolderID, &row.CreatedAt, &row.UpdatedAt, &row.OcrText)
|
||||
err := scan(&row.ID, &row.Name, &row.Size, &row.MimeType, &row.FolderID, &row.CreatedAt, &row.UpdatedAt, &row.OcrText, &row.HasContent)
|
||||
return row, err
|
||||
}
|
||||
|
||||
@@ -500,9 +501,10 @@ func (r *Resources) UpdateNameByID(resourceID, name string) error {
|
||||
// (size_bytes / mime_type / extension) after a targeted re-upload — used so a
|
||||
// resource created metadata-only (outbox create_resource) receives its bytes
|
||||
// for server-side OCR. Absent / not owned → ErrNotFound. Never renames or moves.
|
||||
// Des octets viennent d'arriver : `has_content` passe à TRUE (V2 lazy).
|
||||
func (r *Resources) UpdatePhysical(ownerID, resourceID string, size int64, mimeType, extension *string) error {
|
||||
result, err := r.DB.Exec(
|
||||
`UPDATE resources SET size_bytes = $3, mime_type = $4, extension = $5, updated_at = NOW()
|
||||
`UPDATE resources SET size_bytes = $3, mime_type = $4, extension = $5, has_content = TRUE, updated_at = NOW()
|
||||
WHERE resource_id = $1 AND user_id = $2 AND type = 'file' AND deleted_at IS NULL`,
|
||||
resourceID, ownerID, size, mimeType, extension,
|
||||
)
|
||||
@@ -519,6 +521,28 @@ func (r *Resources) UpdatePhysical(ownerID, resourceID string, size int64, mimeT
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetHasContent flips the V2 `has_content` flag (lazy healing) : TRUE quand
|
||||
// des octets sont constatés (upload, OpenContent réussi), FALSE quand ils ont
|
||||
// disparu sous UPLOAD_DIR. Best-effort côté service (jamais d'erreur vers le
|
||||
// client). Absent / not owned → ErrNotFound (ignoré par l'appelant).
|
||||
func (r *Resources) SetHasContent(ownerID, resourceID string, has bool) error {
|
||||
result, err := r.DB.Exec(
|
||||
`UPDATE resources SET has_content = $3, updated_at = NOW()
|
||||
WHERE resource_id = $1 AND user_id = $2 AND type = 'file' AND deleted_at IS NULL`,
|
||||
resourceID, ownerID, has,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// UpdateOcrText writes the server-computed OCR extract onto the resource
|
||||
// (owner-scoped, bumping updated_at so the change flows through the sync
|
||||
// snapshot). The text is then readable by every device of the user AND by
|
||||
|
||||
Reference in New Issue
Block a user