Correct retry and timeout for QR websocket
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import datetime
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Awaitable, Callable
|
from typing import TYPE_CHECKING, Awaitable, Callable
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -542,19 +543,33 @@ class ProvisioningAPI(AuthAPI):
|
|||||||
ws = web.WebSocketResponse(protocols=["net.maunium.telegram.login"])
|
ws = web.WebSocketResponse(protocols=["net.maunium.telegram.login"])
|
||||||
await ws.prepare(request)
|
await ws.prepare(request)
|
||||||
|
|
||||||
|
retries = 0
|
||||||
user_info = None
|
user_info = None
|
||||||
try:
|
while retries < 4:
|
||||||
await qr_login.recreate()
|
try:
|
||||||
await ws.send_json({"code": qr_login.url, "timeout": 30})
|
await qr_login.recreate()
|
||||||
user_info = await qr_login.wait()
|
await ws.send_json(
|
||||||
except asyncio.TimeoutError:
|
{
|
||||||
|
"code": qr_login.url,
|
||||||
|
"timeout": int(
|
||||||
|
(
|
||||||
|
qr_login.expires - datetime.datetime.now(tz=datetime.timezone.utc)
|
||||||
|
).total_seconds()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
user_info = await qr_login.wait()
|
||||||
|
break
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
retries += 1
|
||||||
|
except SessionPasswordNeededError:
|
||||||
|
await ws.send_json({"success": False, "error": "password-needed"})
|
||||||
|
await ws.close()
|
||||||
|
return ws
|
||||||
|
else:
|
||||||
await ws.send_json({"success": False, "error": "timeout"})
|
await ws.send_json({"success": False, "error": "timeout"})
|
||||||
await ws.close()
|
await ws.close()
|
||||||
return ws
|
return ws
|
||||||
except SessionPasswordNeededError:
|
|
||||||
await ws.send_json({"success": False, "error": "password-needed"})
|
|
||||||
await ws.close()
|
|
||||||
return ws
|
|
||||||
|
|
||||||
await self.postprocess_login(user, user_info)
|
await self.postprocess_login(user, user_info)
|
||||||
await ws.send_json({"success": True})
|
await ws.send_json({"success": True})
|
||||||
|
|||||||
Reference in New Issue
Block a user