aukpad-paste-proxy/main.py
2025-10-17 22:38:32 +02:00

63 lines
No EOL
2.5 KiB
Python

from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse
import httpx
import asyncio
import os
app = FastAPI(title="Aukpad Proxy Service", description="Proxy service for aukpad.com to linedump.com")
# Configuration from environment variables
PAD_DOMAIN = os.getenv("PAD_DOMAIN", "aukpad.com")
DUMP_DOMAIN = os.getenv("DUMP_DOMAIN", "linedump.com")
PROXY_DOMAIN = os.getenv("PROXY_DOMAIN", "bin.aukpad.com")
@app.get("/{paste_id}")
async def proxy_paste(paste_id: str):
try:
# Fetch content from pad domain
pad_url = f"https://{PAD_DOMAIN}/{paste_id}/raw"
async with httpx.AsyncClient() as client:
# Get content from pad
pad_response = await client.get(pad_url)
pad_response.raise_for_status()
content = pad_response.text
# Post content to dump domain
dump_response = await client.post(
f"https://{DUMP_DOMAIN}",
data=content,
headers={"Content-Type": "text/plain"}
)
dump_response.raise_for_status()
# linedump.com returns the full URL in the response body
dump_url = dump_response.text.strip()
# Redirect to the dump URL
return RedirectResponse(url=dump_url, status_code=302)
except httpx.HTTPStatusError as e:
raise HTTPException(status_code=e.response.status_code, detail=f"Error fetching from external service: {str(e)}")
except httpx.RequestError as e:
raise HTTPException(status_code=500, detail=f"Network error: {str(e)}")
except Exception as e:
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
@app.get("/")
async def root():
return {
"service": "Aukpad Proxy Service",
"description": f"This service proxies paste content from {PAD_DOMAIN} to {DUMP_DOMAIN}",
"usage": f"Visit https://{PROXY_DOMAIN}/{{paste_id}} to fetch content from https://{PAD_DOMAIN}/{{paste_id}}/raw and redirect to the posted URL on {DUMP_DOMAIN}",
"example": f"https://{PROXY_DOMAIN}/abc123 → fetches https://{PAD_DOMAIN}/abc123/raw → posts to https://{DUMP_DOMAIN} → redirects to result URL",
"domains": {
"proxy": PROXY_DOMAIN,
"source": PAD_DOMAIN,
"destination": DUMP_DOMAIN
}
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)