from fastapi import FastAPI, HTTPException, Query, File, UploadFile from fastapi.responses import PlainTextResponse, HTMLResponse import subprocess import os import shutil app = FastAPI() print("--- NEW VERSION STARTING ---") SECURITY_TOKEN = os.getenv("SECURITY_TOKEN") @app.get("/") def read_root(): return {"status": "online", "message": "TermX API is running"} @app.get("/termx", response_class=PlainTextResponse) def run_command(cmd: str = Query(...), token: str = Query(...)): if token != SECURITY_TOKEN: raise HTTPException(status_code=403, detail="Invalid Token!") try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True) return result.stdout if result.stdout else result.stderr except Exception as e: return f"Error: {str(e)}" # ফাইল আপলোড এন্ডপয়েন্ট @app.post("/upload") async def upload_file(token: str = Query(...), file: UploadFile = File(...)): if token != SECURITY_TOKEN: raise HTTPException(status_code=403, detail="Invalid Token!") try: file_path = os.path.join(os.getcwd(), file.filename) with open(file_path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) return {"message": f"Successfully uploaded {file.filename}"} except Exception as e: return {"error": str(e)} # ========================= # ✅ NEW FUNCTION (ADDED) # ========================= @app.get("/openweb", response_class=HTMLResponse) def open_web(token: str = Query(...)): if token != SECURITY_TOKEN: raise HTTPException(status_code=403, detail="Invalid Token!") return """ Modern File Upload

📁 File Upload

cloud_upload

Click or Drag file here

"""