| """Cloud Browser API V2 - RESTful feature-based structure.""" |
|
|
| import asyncio |
| import importlib |
| import inspect |
| import logging |
| import os |
| import pkgutil |
| import sys |
| import traceback |
| from contextlib import asynccontextmanager |
| from typing import List, Dict, Any, Optional |
|
|
| from fastapi import Depends, FastAPI, WebSocket, APIRouter |
| from fastapi.middleware.cors import CORSMiddleware |
| from fastapi.openapi.docs import get_swagger_ui_html |
| from fastapi.openapi.utils import get_openapi |
| from fastapi.responses import HTMLResponse |
|
|
| |
| logging.basicConfig(level=logging.INFO) |
| logger = logging.getLogger(__name__) |
|
|
|
|
| @asynccontextmanager |
| async def lifespan(app: FastAPI): |
| """Application lifecycle manager.""" |
| logger.info("Starting Cloud") |
|
|
| yield |
|
|
| logger.info("Cloud shutdown") |
|
|
|
|
| |
| app = FastAPI( |
| title="Cloud Browser API", |
| description=""" |
| # Cloud Browser API Documentation |
| |
| API này cung cấp các endpoint để quản lý và điều khiển các trình duyệt ảo trên đám mây. |
| Bạn có thể tạo, quản lý và tương tác với các phiên trình duyệt thông qua API này. |
| |
| ## Tính năng chính |
| |
| * Tạo và quản lý các phiên trình duyệt |
| * Điều khiển trình duyệt qua WebSocket |
| * Thực hiện các tác vụ tự động hóa |
| * Quản lý tiện ích mở rộng trình duyệt |
| |
| ## Authentication |
| |
| API này sử dụng token-based authentication. Vui lòng liên hệ với quản trị viên để được cấp token. |
| """, |
| version="2.0.0", |
| lifespan=lifespan, |
| docs_url="/docs", |
| openapi_url="/openapi.json", |
| contact={ |
| "name": "API Support", |
| "url": "http://example.com/support", |
| "email": "support@example.com", |
| }, |
| license_info={ |
| "name": "Proprietary", |
| "url": "http://example.com/license", |
| }, |
| ) |
|
|
| |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
|
|
| @app.get("/ping") |
| def api_status(): |
| """Check API status.""" |
| return {"status": "ok", "version": "2.0.0"} |
|
|