from fastapi import FastAPI, HTTPException, Query from fastapi.middleware.cors import CORSMiddleware import httpx app = FastAPI() # Konfigurasi CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], # Anda dapat mengganti "*" dengan daftar asal yang diizinkan allow_credentials=True, allow_methods=["*"], # Anda dapat mengganti "*" dengan daftar metode yang diizinkan allow_headers=["*"], # Anda dapat mengganti "*" dengan daftar header yang diizinkan ) @app.get("/") def read_root(): return {"message": "Hello World!"} @app.get("/file/list") async def get_file_list( key: str, page: int = Query(1, alias='page'), # default page to 1 per_page: int = Query(100, alias='per_page') # default per_page to 10 ): url = f"https://doodapi.com/api/file/list?key={key}&page={page}&per_page={per_page}" async with httpx.AsyncClient() as client: response = await client.get(url) if response.status_code == 200: return response.json() else: raise HTTPException(status_code=response.status_code, detail="Error fetching data from doodapi.com") @app.get("/file/info") async def get_file_info( key: str, file_code: str ): url = f"https://doodapi.com/api/file/info?key={key}&file_code={file_code}" async with httpx.AsyncClient() as client: response = await client.get(url) if response.status_code == 200: return response.json() else: raise HTTPException(status_code=response.status_code, detail="Error fetching data from doodapi.com") @app.get("/search/videos") async def search_videos( key: str, search_term: str ): url = f"https://doodapi.com/api/search/videos?key={key}&search_term={search_term}" async with httpx.AsyncClient() as client: response = await client.get(url) if response.status_code == 200: return response.json() else: raise HTTPException(status_code=response.status_code, detail="Error fetching data from doodapi.com")