fetch actual filename rather than bad placeholder

This commit is contained in:
Taylor Wilsdon
2025-06-18 18:07:50 -04:00
parent 9be4d8da7e
commit cd5ab74472

View File

@@ -268,6 +268,7 @@ async def create_event(
event_body["end"]["timeZone"] = timezone event_body["end"]["timeZone"] = timezone
if attendees: if attendees:
event_body["attendees"] = [{"email": email} for email in attendees] event_body["attendees"] = [{"email": email} for email in attendees]
if attachments: if attachments:
# Accept both file URLs and file IDs. If a URL, extract the fileId. # Accept both file URLs and file IDs. If a URL, extract the fileId.
event_body["attachments"] = [] event_body["attachments"] = []
@@ -290,18 +291,25 @@ async def create_event(
if file_id: if file_id:
file_url = f"https://drive.google.com/open?id={file_id}" file_url = f"https://drive.google.com/open?id={file_id}"
mime_type = "application/vnd.google-apps.drive-sdk" mime_type = "application/vnd.google-apps.drive-sdk"
# Try to get the actual MIME type from Drive title = "Drive Attachment"
# Try to get the actual MIME type and filename from Drive
if drive_service: if drive_service:
try: try:
file_metadata = await asyncio.to_thread( file_metadata = await asyncio.to_thread(
drive_service.files().get(fileId=file_id, fields="mimeType").execute drive_service.files().get(fileId=file_id, fields="mimeType,name").execute
) )
mime_type = file_metadata.get("mimeType", mime_type) mime_type = file_metadata.get("mimeType", mime_type)
filename = file_metadata.get("name")
if filename:
title = filename
logger.info(f"[create_event] Using filename '{filename}' as attachment title")
else:
logger.info(f"[create_event] No filename found, using generic title")
except Exception as e: except Exception as e:
logger.warning(f"Could not fetch MIME type for file {file_id}: {e}") logger.warning(f"Could not fetch metadata for file {file_id}: {e}")
event_body["attachments"].append({ event_body["attachments"].append({
"fileUrl": file_url, "fileUrl": file_url,
"title": f"Drive Attachment ({file_id})", "title": title,
"mimeType": mime_type, "mimeType": mime_type,
}) })
created_event = await asyncio.to_thread( created_event = await asyncio.to_thread(