CoolFace
Apppublic

sjsotere11/mp4loop

sourceHugging Faceupdated 9d agoView on Hugging Face
0likes
app.py58 linesDownload Raw Back to root
1from fastapi import FastAPI, Request2from fastapi.responses import Response, FileResponse3import httpx4import os5 6app = FastAPI()7LOG_FILE = "app_requests_log.txt"8 9@app.get("/get-logs")10def download_logs():11    if os.path.exists(LOG_FILE):12        return FileResponse(LOG_FILE, media_type='text/plain', filename="app_requests_log.txt")13    return {"message": "Logs khali hain."}14 15@app.api_route("/{path:path}", methods=["GET", "POST", "PUT"])16async def proxy_logger(request: Request, path: str):17    # App ka bheja hua POST data (Body) catch karein18    body_bytes = await request.body()19    body_str = body_bytes.decode('utf-8', errors='ignore')20    21    with open(LOG_FILE, "a", encoding="utf-8") as f:22        f.write("========== APP KI REQUEST ==========\n")23        f.write(f"PATH: /{path}\n")24        f.write(f"METHOD: {request.method}\n")25        f.write(f"BODY DATA: {body_str}\n")26    27    target_url = f"https://filex.fit/{path}"28    29    # App ke original headers pass karein taake server block na kare30    headers = {31        "User-Agent": request.headers.get("user-agent", "Dalvik/2.1.0 (Linux; U; Android 11)")32    }33    if "content-type" in request.headers:34        headers["Content-Type"] = request.headers["content-type"]35 36    try:37        async with httpx.AsyncClient(verify=False) as client:38            if request.method == "POST":39                response = await client.post(target_url, params=request.query_params, content=body_bytes, headers=headers)40            else:41                response = await client.get(target_url, params=request.query_params, headers=headers)42            43            # Original Server ka Response (JSON) save karein44            with open(LOG_FILE, "a", encoding="utf-8") as f:45                f.write(f"RESPONSE STATUS: {response.status_code}\n")46                f.write(f"ASLI JSON RESPONSE:\n{response.text}\n")47                f.write("==================================\n\n")48            49            return Response(50                content=response.content, 51                status_code=response.status_code, 52                media_type=response.headers.get("content-type")53            )54            55    except Exception as e:56        with open(LOG_FILE, "a", encoding="utf-8") as f:57            f.write(f"ERROR: {str(e)}\n==================================\n\n")58        return Response(content=f"Error: {str(e)}", status_code=500)