V2 : flag serveur has_content (migration 000014, lazy healing, FileDto)
This commit is contained in:
@@ -24,14 +24,15 @@ var ErrInvalidUpload = errors.New("invalid upload name")
|
||||
|
||||
// FileDTO serializes exactly as mobile/api/types.ts FileDto.
|
||||
type FileDTO struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
FolderID string `json:"folderId,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mimeType,omitempty"`
|
||||
FolderID string `json:"folderId,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
HasContent bool `json:"hasContent"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
// FolderDTO serializes exactly as mobile/api/types.ts FolderDto.
|
||||
@@ -201,8 +202,21 @@ func (s *Resources) OpenContent(userID, resourceID string) (ContentInfo, error)
|
||||
if mime == "" {
|
||||
mime = "application/octet-stream"
|
||||
}
|
||||
// Octets constatés : heal `has_content` → TRUE (V2 lazy, best-effort).
|
||||
if !row.HasContent {
|
||||
if herr := s.Repo.SetHasContent(ownerID, resourceID, true); herr != nil {
|
||||
log.Printf("content: heal has_content(%s): %v", resourceID, herr)
|
||||
}
|
||||
}
|
||||
return ContentInfo{Path: resolved, Name: row.Name, MimeType: mime, Size: fi.Size()}, nil
|
||||
}
|
||||
// Aucun octet mais flag TRUE (suppression manuelle sous UPLOAD_DIR) :
|
||||
// heal → FALSE (V2 lazy, best-effort).
|
||||
if row.HasContent {
|
||||
if herr := s.Repo.SetHasContent(ownerID, resourceID, false); herr != nil {
|
||||
log.Printf("content: heal has_content(%s): %v", resourceID, herr)
|
||||
}
|
||||
}
|
||||
return ContentInfo{}, repository.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -327,6 +341,10 @@ func (s *Resources) Upload(ownerID string, file *multipart.FileHeader, folderID,
|
||||
err = s.Repo.UpdatePhysical(ownerID, resourceID, written, &mimeType, extPtr)
|
||||
} else {
|
||||
err = s.Repo.InsertFile(ownerID, resourceID, name, folderID, written, &mimeType, extPtr)
|
||||
if err == nil {
|
||||
// Upload avec octets : `has_content` TRUE (V2 lazy).
|
||||
err = s.Repo.SetHasContent(ownerID, resourceID, true)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
// Best-effort : supprime le nouveau fichier sauf s'il préexistait à l'identique.
|
||||
@@ -422,12 +440,13 @@ func copyMultipartAtomic(file *multipart.FileHeader, destDir, destPath string, m
|
||||
|
||||
func toFileDTO(row repository.FileRow) FileDTO {
|
||||
return FileDTO{
|
||||
ID: row.ID,
|
||||
Name: row.Name,
|
||||
Size: row.Size,
|
||||
MimeType: row.MimeType,
|
||||
FolderID: row.FolderID,
|
||||
CreatedAt: row.CreatedAt.UTC().Format(time.RFC3339),
|
||||
UpdatedAt: row.UpdatedAt.UTC().Format(time.RFC3339),
|
||||
ID: row.ID,
|
||||
Name: row.Name,
|
||||
Size: row.Size,
|
||||
MimeType: row.MimeType,
|
||||
FolderID: row.FolderID,
|
||||
HasContent: row.HasContent,
|
||||
CreatedAt: row.CreatedAt.UTC().Format(time.RFC3339),
|
||||
UpdatedAt: row.UpdatedAt.UTC().Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user