Spaces:
Sleeping
Sleeping
Create server.py
Browse files
server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from fastapi import FastAPI, Header, HTTPException, Request
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Get the Secret from Hugging Face Settings
|
| 9 |
+
API_KEY = os.getenv("API_KEY")
|
| 10 |
+
|
| 11 |
+
class EncryptedSignal(BaseModel):
|
| 12 |
+
recipient_id: str
|
| 13 |
+
encrypted_blob: str # The E2EE data from AIDE
|
| 14 |
+
type: str = "signal"
|
| 15 |
+
|
| 16 |
+
@app.get("/")
|
| 17 |
+
def health_check():
|
| 18 |
+
return {"status": "Teamer Python Server is Online", "blind": True}
|
| 19 |
+
|
| 20 |
+
@app.post("/api/push")
|
| 21 |
+
async def push_signal(
|
| 22 |
+
signal: EncryptedSignal,
|
| 23 |
+
x_api_key: Optional[str] = Header(None)
|
| 24 |
+
):
|
| 25 |
+
# 1. Security Check
|
| 26 |
+
if not x_api_key or x_api_key != API_KEY:
|
| 27 |
+
print("Unauthorized access attempt blocked.")
|
| 28 |
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 29 |
+
|
| 30 |
+
# 2. Blind Routing Logic
|
| 31 |
+
# The server only sees who it is for, not what is inside.
|
| 32 |
+
print(f"Routing encrypted payload to: {signal.recipient_id}")
|
| 33 |
+
|
| 34 |
+
# In a full app, you would push this to a DB (like MongoDB or Supabase)
|
| 35 |
+
return {
|
| 36 |
+
"success": True,
|
| 37 |
+
"message": "Blob routed",
|
| 38 |
+
"timestamp": os.getloadavg() # Just a dummy metric
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
import uvicorn
|
| 43 |
+
# Hugging Face uses port 7860 by default
|
| 44 |
+
port = int(os.getenv("PORT", 7860))
|
| 45 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|