|
1 | | -from fastapi import APIRouter, Request, HTTPException, Response, Depends, Form, UploadFile, File |
2 | | -from app.logic.data import check_new_data, data_processor |
| 1 | +from fastapi import APIRouter, Request, HTTPException, Response, Depends, Form, UploadFile, File, Query |
| 2 | +from app.logic.data import check_new_data, delete_data, data_processor |
3 | 3 | from app.utils.jwt import verify_jwt_token |
4 | 4 | from app.core.constants import LONGPOLL_MAX |
| 5 | +from typing import Optional |
5 | 6 | import asyncio |
6 | 7 | import json |
7 | 8 |
|
8 | 9 | router = APIRouter() |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @router.get("/data/longpoll") |
12 | | -async def get_data_longpoll(request: Request, response: Response, user=Depends(verify_jwt_token)): |
| 13 | +async def get_data_longpoll(request: Request, response: Response, acks: Optional[list[str]] = Query(None), user=Depends(verify_jwt_token)): |
| 14 | + if acks: |
| 15 | + await asyncio.to_thread(delete_data, user["id"], acks) |
| 16 | + |
13 | 17 | for _ in range(LONGPOLL_MAX): |
14 | 18 | if await request.is_disconnected(): |
15 | | - # Don't attempt to check for new data if client disconnects before LONGPOLL_MAX seconds |
16 | | - # This is crucial to perserve data as they get deleted after being read |
| 19 | + # Don't bother checking for new data if client disconnects before LONGPOLL_MAX seconds |
17 | 20 | return Response(content=b'', media_type="application/octet-stream") |
18 | 21 |
|
19 | 22 | data = await asyncio.to_thread(check_new_data, user["id"]) |
|
0 commit comments