Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,13 +50,25 @@ async def shutdown():
|
|
| 50 |
if worker: worker.cancel()
|
| 51 |
if drv: drv.quit()
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
@app.get("/healthz")
|
| 54 |
async def health():
|
| 55 |
return {"ok": True}
|
| 56 |
|
| 57 |
-
|
| 58 |
-
async def open_url(payload: OpenPayload, x_opener_key: str | None = Header(default=None)):
|
| 59 |
if API_KEY and x_opener_key != API_KEY:
|
| 60 |
raise HTTPException(status_code=401, detail="bad key")
|
|
|
|
| 61 |
await queue.put(str(payload.url))
|
| 62 |
return Response(status_code=204)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
if worker: worker.cancel()
|
| 51 |
if drv: drv.quit()
|
| 52 |
|
| 53 |
+
@app.get("/")
|
| 54 |
+
async def root():
|
| 55 |
+
return {"ok": True}
|
| 56 |
+
|
| 57 |
@app.get("/healthz")
|
| 58 |
async def health():
|
| 59 |
return {"ok": True}
|
| 60 |
|
| 61 |
+
async def _enqueue(payload: OpenPayload, x_opener_key: str | None):
|
|
|
|
| 62 |
if API_KEY and x_opener_key != API_KEY:
|
| 63 |
raise HTTPException(status_code=401, detail="bad key")
|
| 64 |
+
print("[recv]", str(payload.url))
|
| 65 |
await queue.put(str(payload.url))
|
| 66 |
return Response(status_code=204)
|
| 67 |
+
|
| 68 |
+
@app.post("/open")
|
| 69 |
+
async def open_url(payload: OpenPayload, x_opener_key: str | None = Header(default=None)):
|
| 70 |
+
return await _enqueue(payload, x_opener_key)
|
| 71 |
+
|
| 72 |
+
@app.post("/")
|
| 73 |
+
async def open_root(payload: OpenPayload, x_opener_key: str | None = Header(default=None)):
|
| 74 |
+
return await _enqueue(payload, x_opener_key)
|