File size: 839 Bytes
ebc54c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cloudinary
from cloudinary import Search
from app.core.config import settings

# Configure
cloudinary.config(
    cloud_name=settings.CLOUDINARY_CLOUD_NAME,
    api_key=settings.CLOUDINARY_API_KEY,
    api_secret=settings.CLOUDINARY_API_SECRET,
    secure=True
)

def get_resume_url(thread_id: str) -> str:
    """
    Searches Cloudinary for the resume PDF in the thread's folder
    and returns the secure URL.
    """
    result = Search() \
        .expression(f'folder:"threads/{thread_id}/*"') \
        .sort_by('public_id', 'desc') \
        .max_results(1) \
        .execute()

    resources = result.get("resources", [])

    if not resources:
        raise FileNotFoundError(f"No resume found for thread_id: {thread_id}")

    pdf_url = resources[0]["secure_url"]
    print(f"Found resume: {pdf_url}")
    return pdf_url