diff --git a/app/api/endpoints/meetings.py b/app/api/endpoints/meetings.py index bf3e8ec..7ce8cf4 100644 --- a/app/api/endpoints/meetings.py +++ b/app/api/endpoints/meetings.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, HTTPException, UploadFile, File, Form from app.models.models import Meeting, TranscriptSegment, CreateMeetingRequest, UpdateMeetingRequest from app.core.database import get_db_connection -from app.core.config import UPLOAD_DIR, AUDIO_DIR, ALLOWED_EXTENSIONS, MAX_FILE_SIZE +from app.core.config import UPLOAD_DIR, AUDIO_DIR, MARKDOWN_DIR, ALLOWED_EXTENSIONS, ALLOWED_IMAGE_EXTENSIONS, MAX_FILE_SIZE, MAX_IMAGE_SIZE from typing import Optional import os import uuid @@ -392,3 +392,55 @@ def get_audio_file(meeting_id: int): "file_size": audio_file['file_size'], "upload_time": audio_file['upload_time'] } + +@router.post("/meetings/{meeting_id}/upload-image") +async def upload_image( + meeting_id: int, + image_file: UploadFile = File(...) +): + # Validate file extension + file_extension = os.path.splitext(image_file.filename)[1].lower() + if file_extension not in ALLOWED_IMAGE_EXTENSIONS: + raise HTTPException( + status_code=400, + detail=f"Unsupported image type. Allowed types: {', '.join(ALLOWED_IMAGE_EXTENSIONS)}" + ) + + # Check file size + if image_file.size > MAX_IMAGE_SIZE: + raise HTTPException( + status_code=400, + detail="Image size exceeds 10MB limit" + ) + + # Check if meeting exists + with get_db_connection() as connection: + cursor = connection.cursor(dictionary=True) + cursor.execute("SELECT meeting_id FROM meetings WHERE meeting_id = %s", (meeting_id,)) + if not cursor.fetchone(): + raise HTTPException(status_code=404, detail="Meeting not found") + + # Create meeting-specific directory + meeting_dir = MARKDOWN_DIR / str(meeting_id) + meeting_dir.mkdir(exist_ok=True) + + # Generate unique filename + unique_filename = f"{uuid.uuid4()}{file_extension}" + file_path = meeting_dir / unique_filename + + # Store relative path for URL access + relative_path = f"markdown/{meeting_id}/{unique_filename}" + + # Save file + try: + with open(file_path, "wb") as buffer: + shutil.copyfileobj(image_file.file, buffer) + except Exception as e: + raise HTTPException(status_code=500, detail=f"Failed to save image: {str(e)}") + + return { + "message": "Image uploaded successfully", + "file_name": image_file.filename, + "file_path": relative_path, + "url": f"/uploads/{relative_path}" + } diff --git a/app/core/config.py b/app/core/config.py index 7e0968d..84de2c2 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -5,14 +5,18 @@ from pathlib import Path BASE_DIR = Path(__file__).parent.parent.parent UPLOAD_DIR = BASE_DIR / "uploads" AUDIO_DIR = UPLOAD_DIR / "audio" +MARKDOWN_DIR = UPLOAD_DIR / "markdown" # 文件上传配置 ALLOWED_EXTENSIONS = {".mp3", ".wav", ".m4a", ".mpeg", ".mp4"} +ALLOWED_IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"} MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB +MAX_IMAGE_SIZE = 10 * 1024 * 1024 # 10MB # 确保上传目录存在 UPLOAD_DIR.mkdir(exist_ok=True) AUDIO_DIR.mkdir(exist_ok=True) +MARKDOWN_DIR.mkdir(exist_ok=True) # 数据库配置 DATABASE_CONFIG = { diff --git a/uploads/.DS_Store b/uploads/.DS_Store index 73c98ca..336ea78 100644 Binary files a/uploads/.DS_Store and b/uploads/.DS_Store differ diff --git a/uploads/markdown/13/1125df5d-1532-4ef5-a5eb-627d2f99156d.jpg b/uploads/markdown/13/1125df5d-1532-4ef5-a5eb-627d2f99156d.jpg new file mode 100644 index 0000000..bad02a8 Binary files /dev/null and b/uploads/markdown/13/1125df5d-1532-4ef5-a5eb-627d2f99156d.jpg differ diff --git a/uploads/markdown/14/6ca04747-537b-463d-be6a-a60f3109e67e.png b/uploads/markdown/14/6ca04747-537b-463d-be6a-a60f3109e67e.png new file mode 100644 index 0000000..6c0b6da Binary files /dev/null and b/uploads/markdown/14/6ca04747-537b-463d-be6a-a60f3109e67e.png differ