Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
HF Space — API principale
|
| 3 |
"""
|
| 4 |
|
| 5 |
import os
|
|
@@ -23,7 +23,7 @@ from orchestrator import Orchestrator
|
|
| 23 |
|
| 24 |
WORKER_URL = os.environ.get(
|
| 25 |
"WORKER_URL",
|
| 26 |
-
"https://
|
| 27 |
)
|
| 28 |
|
| 29 |
pool = ProxyPool()
|
|
@@ -55,7 +55,7 @@ def self_ping():
|
|
| 55 |
|
| 56 |
@asynccontextmanager
|
| 57 |
async def lifespan(app: FastAPI):
|
| 58 |
-
logger.info("🚀 Proxy API")
|
| 59 |
logger.info(f" Worker: {WORKER_URL}")
|
| 60 |
|
| 61 |
scheduler.add_job(
|
|
@@ -105,6 +105,7 @@ async def root():
|
|
| 105 |
"version": "3.0.0",
|
| 106 |
"pool": pool.size,
|
| 107 |
"worker_ok": orch._worker_ok,
|
|
|
|
| 108 |
"docs": "/docs",
|
| 109 |
}
|
| 110 |
|
|
@@ -139,9 +140,7 @@ async def get_proxy(
|
|
| 139 |
}
|
| 140 |
f = funcs.get(strategy)
|
| 141 |
if not f:
|
| 142 |
-
raise HTTPException(
|
| 143 |
-
400, f"Strategies: {list(funcs.keys())}"
|
| 144 |
-
)
|
| 145 |
return _resp(f(protocol, verified), strategy)
|
| 146 |
|
| 147 |
|
|
@@ -171,7 +170,8 @@ async def least(
|
|
| 171 |
verified: bool = Query(False),
|
| 172 |
):
|
| 173 |
return _resp(
|
| 174 |
-
pool.get_least_used(protocol, verified),
|
|
|
|
| 175 |
)
|
| 176 |
|
| 177 |
|
|
@@ -193,17 +193,14 @@ async def rotate(
|
|
| 193 |
break
|
| 194 |
if not results:
|
| 195 |
raise HTTPException(503, "No proxies")
|
| 196 |
-
return {
|
| 197 |
-
"count": len(results),
|
| 198 |
-
"proxies": results,
|
| 199 |
-
}
|
| 200 |
|
| 201 |
|
| 202 |
@app.get("/all")
|
| 203 |
async def get_all(
|
| 204 |
protocol: str = Query(None),
|
| 205 |
verified: bool = Query(False),
|
| 206 |
-
limit: int = Query(200, le=
|
| 207 |
):
|
| 208 |
px = pool.get_all(protocol, verified, limit)
|
| 209 |
return {"count": len(px), "proxies": px}
|
|
@@ -213,7 +210,7 @@ async def get_all(
|
|
| 213 |
async def plain(
|
| 214 |
protocol: str = Query(None),
|
| 215 |
verified: bool = Query(False),
|
| 216 |
-
limit: int = Query(200, le=
|
| 217 |
):
|
| 218 |
px = pool.get_all(protocol, verified, limit)
|
| 219 |
return PlainTextResponse(
|
|
@@ -236,10 +233,8 @@ async def feedback(
|
|
| 236 |
@app.post("/force-check")
|
| 237 |
async def force():
|
| 238 |
if orch._phase.value != "idle":
|
| 239 |
-
return {"status":
|
| 240 |
-
threading.Thread(
|
| 241 |
-
target=do_tick, daemon=True
|
| 242 |
-
).start()
|
| 243 |
return {"status": "started"}
|
| 244 |
|
| 245 |
|
|
|
|
| 1 |
"""
|
| 2 |
+
HF Space — API principale v2
|
| 3 |
"""
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 23 |
|
| 24 |
WORKER_URL = os.environ.get(
|
| 25 |
"WORKER_URL",
|
| 26 |
+
"https://iptest-u2uk.onrender.com"
|
| 27 |
)
|
| 28 |
|
| 29 |
pool = ProxyPool()
|
|
|
|
| 55 |
|
| 56 |
@asynccontextmanager
|
| 57 |
async def lifespan(app: FastAPI):
|
| 58 |
+
logger.info("🚀 Proxy API v2")
|
| 59 |
logger.info(f" Worker: {WORKER_URL}")
|
| 60 |
|
| 61 |
scheduler.add_job(
|
|
|
|
| 105 |
"version": "3.0.0",
|
| 106 |
"pool": pool.size,
|
| 107 |
"worker_ok": orch._worker_ok,
|
| 108 |
+
"phase": orch._phase.value,
|
| 109 |
"docs": "/docs",
|
| 110 |
}
|
| 111 |
|
|
|
|
| 140 |
}
|
| 141 |
f = funcs.get(strategy)
|
| 142 |
if not f:
|
| 143 |
+
raise HTTPException(400, "Bad strategy")
|
|
|
|
|
|
|
| 144 |
return _resp(f(protocol, verified), strategy)
|
| 145 |
|
| 146 |
|
|
|
|
| 170 |
verified: bool = Query(False),
|
| 171 |
):
|
| 172 |
return _resp(
|
| 173 |
+
pool.get_least_used(protocol, verified),
|
| 174 |
+
"least-used",
|
| 175 |
)
|
| 176 |
|
| 177 |
|
|
|
|
| 193 |
break
|
| 194 |
if not results:
|
| 195 |
raise HTTPException(503, "No proxies")
|
| 196 |
+
return {"count": len(results), "proxies": results}
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
|
| 199 |
@app.get("/all")
|
| 200 |
async def get_all(
|
| 201 |
protocol: str = Query(None),
|
| 202 |
verified: bool = Query(False),
|
| 203 |
+
limit: int = Query(200, le=1000),
|
| 204 |
):
|
| 205 |
px = pool.get_all(protocol, verified, limit)
|
| 206 |
return {"count": len(px), "proxies": px}
|
|
|
|
| 210 |
async def plain(
|
| 211 |
protocol: str = Query(None),
|
| 212 |
verified: bool = Query(False),
|
| 213 |
+
limit: int = Query(200, le=1000),
|
| 214 |
):
|
| 215 |
px = pool.get_all(protocol, verified, limit)
|
| 216 |
return PlainTextResponse(
|
|
|
|
| 233 |
@app.post("/force-check")
|
| 234 |
async def force():
|
| 235 |
if orch._phase.value != "idle":
|
| 236 |
+
return {"status": orch._phase.value}
|
| 237 |
+
threading.Thread(target=do_tick, daemon=True).start()
|
|
|
|
|
|
|
| 238 |
return {"status": "started"}
|
| 239 |
|
| 240 |
|