Merge pull request #288 from joshed-io/feat/gmail-attachment-http-serving

Add HTTP URL-based Attachment Serving for Gmail Attachments
This commit is contained in:
Taylor Wilsdon
2025-12-08 09:49:36 -05:00
committed by GitHub
4 changed files with 357 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ import socket
import uvicorn
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse, JSONResponse
from typing import Optional
from urllib.parse import urlparse
@@ -39,6 +40,8 @@ class MinimalOAuthServer:
# Setup the callback route
self._setup_callback_route()
# Setup attachment serving route
self._setup_attachment_route()
def _setup_callback_route(self):
"""Setup the OAuth callback route."""
@@ -89,6 +92,35 @@ class MinimalOAuthServer:
logger.error(error_message_detail, exc_info=True)
return create_server_error_response(str(e))
def _setup_attachment_route(self):
"""Setup the attachment serving route."""
from core.attachment_storage import get_attachment_storage
@self.app.get("/attachments/{file_id}")
async def serve_attachment(file_id: str, request: Request):
"""Serve a stored attachment file."""
storage = get_attachment_storage()
metadata = storage.get_attachment_metadata(file_id)
if not metadata:
return JSONResponse(
{"error": "Attachment not found or expired"},
status_code=404
)
file_path = storage.get_attachment_path(file_id)
if not file_path:
return JSONResponse(
{"error": "Attachment file not found"},
status_code=404
)
return FileResponse(
path=str(file_path),
filename=metadata["filename"],
media_type=metadata["mime_type"]
)
def start(self) -> tuple[bool, str]:
"""
Start the minimal OAuth server.