import shutil from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware from fastapi import FastAPI, UploadFile, File, BackgroundTasks, Form from typing import Optional from wasabi_settings import settings from db import db from transcoder import process_transcoding_task app = FastAPI() # Allow CORS for all origins (adjust this in production) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/") async def root(): return JSONResponse( content={"status": "ok", "message": "Btube Backend is running!"}, status_code=200 ) @app.post("/api/transcode") async def transcode( background_tasks: BackgroundTasks, public_id: str = Form(...), video_type: str = Form(...), location: str = Form(...), ): db.transcodequeue.insert_one({ "public_id": public_id, "video_type": video_type, "status": "queued" }) # Add background task background_tasks.add_task(process_transcoding_task, public_id, video_type, location) return JSONResponse( content={"status": "queued", "public_id": public_id, "message": "Transcoding started in background"}, status_code=200 )