streaming d'un fichier
This commit is contained in:
@@ -146,6 +146,66 @@ type FileOcrDTO struct {
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
// ContentInfo describes the physical bytes of a file the user can see
|
||||
// (viewer+, own or shared) for GET /files/:id/content (streaming lecture,
|
||||
// jamais persisté côté client en V1 streaming).
|
||||
type ContentInfo struct {
|
||||
Path string
|
||||
Name string
|
||||
MimeType string
|
||||
Size int64
|
||||
}
|
||||
|
||||
// OpenContent resolves the physical file of a visible resource. Auth is
|
||||
// viewer+ (GetFileVisible, own or shared) ; the bytes live under the OWNER
|
||||
// dir (UPLOAD_DIR/<owner_id>/<resource_id>.<ext>), never under the requester.
|
||||
// No physical file (metadata-only outbox resource, never uploaded) →
|
||||
// repository.ErrNotFound (handler maps to 404 NOT_FOUND, same as invisible).
|
||||
func (s *Resources) OpenContent(userID, resourceID string) (ContentInfo, error) {
|
||||
row, err := s.Repo.GetFileVisible(userID, resourceID)
|
||||
if err != nil {
|
||||
return ContentInfo{}, err
|
||||
}
|
||||
ownerID, err := s.Repo.GetResourceOwner(resourceID)
|
||||
if err != nil {
|
||||
return ContentInfo{}, err
|
||||
}
|
||||
if !idPattern.MatchString(ownerID) || !idPattern.MatchString(resourceID) {
|
||||
return ContentInfo{}, repository.ErrNotFound
|
||||
}
|
||||
base, err := filepath.EvalSymlinks(s.UploadDir)
|
||||
if err != nil {
|
||||
return ContentInfo{}, repository.ErrNotFound
|
||||
}
|
||||
matches, err := filepath.Glob(filepath.Join(s.UploadDir, ownerID, resourceID+".*"))
|
||||
if err != nil {
|
||||
return ContentInfo{}, repository.ErrNotFound
|
||||
}
|
||||
for _, m := range matches {
|
||||
if !strings.HasPrefix(filepath.Base(m), resourceID+".") {
|
||||
continue
|
||||
}
|
||||
fi, err := os.Lstat(m)
|
||||
if err != nil || !fi.Mode().IsRegular() {
|
||||
continue
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(m)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
rel, err := filepath.Rel(base, resolved)
|
||||
if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
|
||||
continue
|
||||
}
|
||||
mime := row.MimeType
|
||||
if mime == "" {
|
||||
mime = "application/octet-stream"
|
||||
}
|
||||
return ContentInfo{Path: resolved, Name: row.Name, MimeType: mime, Size: fi.Size()}, nil
|
||||
}
|
||||
return ContentInfo{}, repository.ErrNotFound
|
||||
}
|
||||
|
||||
// GetFileOcr returns the OCR text of a file the user can see (viewer+, own or
|
||||
// shared). Absent text → Text empty ("") with 200 (the caller decides).
|
||||
func (s *Resources) GetFileOcr(ownerID, id string) (FileOcrDTO, error) {
|
||||
|
||||
Reference in New Issue
Block a user