File size: 1,278 Bytes
ee7d7b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Shared path utilities for multi-tenant storage
Consolidates duplicate get_user_paths() from endpoints
"""

from pathlib import Path
import os

# Import Settings to get the canonical storage path
from config.settings import Settings

# Detect if running in Docker (Hugging Face Spaces)
if os.path.exists("/app"):
    STORAGE_BASE = Path("/app/storage/users")
else:
    # Use Settings BASE_DIR directly for correct path resolution
    STORAGE_BASE = Settings.BASE_DIR / "storage" / "users"
    STORAGE_BASE.mkdir(parents=True, exist_ok=True)

print(f"Storage Base Path: {STORAGE_BASE.resolve()}")


def get_user_paths(user_id: str) -> dict:
    """
    Get all storage paths for a specific user.
    Creates directories if they don't exist.
    
    Args:
        user_id: Unique user identifier
        
    Returns:
        Dictionary of path objects for user's storage locations
    """
    user_base = STORAGE_BASE / user_id
    paths = {
        "base": user_base,
        "files": user_base / "files",
        "models": user_base / "models",
        "faiss": user_base / "faiss",
        "graph": user_base / "graph",
        "memory": user_base / "memory"
    }
    
    for path in paths.values():
        path.mkdir(parents=True, exist_ok=True)
    
    return paths