Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,3 @@
|
|
| 1 |
-
"""
|
| 2 |
-
HF Space API v3
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
import os
|
| 6 |
import logging
|
| 7 |
import threading
|
|
@@ -57,6 +53,17 @@ def self_ping():
|
|
| 57 |
async def lifespan(app: FastAPI):
|
| 58 |
logger.info("🚀 Proxy API v3")
|
| 59 |
logger.info(f" Worker: {WORKER_URL}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
scheduler.add_job(
|
| 61 |
do_tick, "interval", seconds=30,
|
| 62 |
id="tick", max_instances=1, coalesce=True,
|
|
@@ -70,6 +77,7 @@ async def lifespan(app: FastAPI):
|
|
| 70 |
id="spng", max_instances=1,
|
| 71 |
)
|
| 72 |
scheduler.start()
|
|
|
|
| 73 |
threading.Thread(target=do_tick, daemon=True).start()
|
| 74 |
yield
|
| 75 |
scheduler.shutdown(wait=False)
|
|
@@ -77,7 +85,6 @@ async def lifespan(app: FastAPI):
|
|
| 77 |
|
| 78 |
app = FastAPI(
|
| 79 |
title="🔌 Free Proxy API",
|
| 80 |
-
description="SOCKS5 + HTTP verified",
|
| 81 |
version="3.0.0",
|
| 82 |
lifespan=lifespan,
|
| 83 |
)
|
|
@@ -85,7 +92,7 @@ app = FastAPI(
|
|
| 85 |
|
| 86 |
def _resp(entry, strategy):
|
| 87 |
if entry is None:
|
| 88 |
-
raise HTTPException(503, "No proxy")
|
| 89 |
d = entry.to_dict()
|
| 90 |
d["strategy"] = strategy
|
| 91 |
return d
|
|
@@ -107,6 +114,7 @@ async def health():
|
|
| 107 |
return {
|
| 108 |
"status": "ok" if pool.size > 0 else "warming",
|
| 109 |
"pool": pool.size,
|
|
|
|
| 110 |
}
|
| 111 |
|
| 112 |
|
|
@@ -188,9 +196,7 @@ async def plain(
|
|
| 188 |
limit: int = Query(200, le=1000),
|
| 189 |
):
|
| 190 |
px = pool.get_all(protocol, verified, limit)
|
| 191 |
-
return PlainTextResponse(
|
| 192 |
-
"\n".join(p["proxy_url"] for p in px)
|
| 193 |
-
)
|
| 194 |
|
| 195 |
|
| 196 |
@app.post("/feedback")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import logging
|
| 3 |
import threading
|
|
|
|
| 53 |
async def lifespan(app: FastAPI):
|
| 54 |
logger.info("🚀 Proxy API v3")
|
| 55 |
logger.info(f" Worker: {WORKER_URL}")
|
| 56 |
+
|
| 57 |
+
# charger backup GitHub au démarrage
|
| 58 |
+
try:
|
| 59 |
+
from github_store import load_from_github
|
| 60 |
+
saved = load_from_github()
|
| 61 |
+
if saved:
|
| 62 |
+
pool.import_json(saved)
|
| 63 |
+
logger.info(f"📂 Loaded {pool.size} proxies from GitHub")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.error(f"Backup load: {e}")
|
| 66 |
+
|
| 67 |
scheduler.add_job(
|
| 68 |
do_tick, "interval", seconds=30,
|
| 69 |
id="tick", max_instances=1, coalesce=True,
|
|
|
|
| 77 |
id="spng", max_instances=1,
|
| 78 |
)
|
| 79 |
scheduler.start()
|
| 80 |
+
logger.info("⏰ Tick/30s | WorkerPing/10m | SelfPing/4m")
|
| 81 |
threading.Thread(target=do_tick, daemon=True).start()
|
| 82 |
yield
|
| 83 |
scheduler.shutdown(wait=False)
|
|
|
|
| 85 |
|
| 86 |
app = FastAPI(
|
| 87 |
title="🔌 Free Proxy API",
|
|
|
|
| 88 |
version="3.0.0",
|
| 89 |
lifespan=lifespan,
|
| 90 |
)
|
|
|
|
| 92 |
|
| 93 |
def _resp(entry, strategy):
|
| 94 |
if entry is None:
|
| 95 |
+
raise HTTPException(503, "No proxy available")
|
| 96 |
d = entry.to_dict()
|
| 97 |
d["strategy"] = strategy
|
| 98 |
return d
|
|
|
|
| 114 |
return {
|
| 115 |
"status": "ok" if pool.size > 0 else "warming",
|
| 116 |
"pool": pool.size,
|
| 117 |
+
"worker": orch._worker_ok,
|
| 118 |
}
|
| 119 |
|
| 120 |
|
|
|
|
| 196 |
limit: int = Query(200, le=1000),
|
| 197 |
):
|
| 198 |
px = pool.get_all(protocol, verified, limit)
|
| 199 |
+
return PlainTextResponse("\n".join(p["proxy_url"] for p in px))
|
|
|
|
|
|
|
| 200 |
|
| 201 |
|
| 202 |
@app.post("/feedback")
|