-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (24 loc) · 930 Bytes
/
Copy pathutils.py
File metadata and controls
30 lines (24 loc) · 930 Bytes
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
import os
import uuid
import tempfile
from datetime import datetime
def generate_user_id():
"""Generate a unique user ID"""
return str(uuid.uuid4())
def generate_session_id():
"""Generate a unique session ID"""
return str(uuid.uuid4())
def save_uploaded_file(uploaded_file):
"""Save an uploaded file to a temporary directory"""
# Create a temporary directory if it doesn't exist
temp_dir = os.path.join(tempfile.gettempdir(), "rag_system_uploads")
os.makedirs(temp_dir, exist_ok=True)
# Generate a unique filename
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
file_extension = os.path.splitext(uploaded_file.name)[1]
unique_filename = f"{timestamp}_{uuid.uuid4()}{file_extension}"
file_path = os.path.join(temp_dir, unique_filename)
# Save the file
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
return file_path