Access captcha: special case for websocket

There doesn't seem to be a way to catch a 403 Forbidden error opening a
websocket with JavaScript, so this commit changes the behaviour to this:
open the websocket normally, send one "kick" message, close the
websocket.
このコミットが含まれているのは:
n9k 2022-06-22 08:10:42 +00:00
コミット 4a76fb023e
2個のファイルの変更22行の追加12行の削除

ファイルの表示

@ -9,16 +9,21 @@ from anonstream.websocket import websocket_outbound, websocket_inbound
from anonstream.routes.wrappers import with_user_from
@current_app.websocket('/live')
@with_user_from(websocket)
async def live(timestamp, user):
queue = asyncio.Queue()
user['websockets'][queue] = timestamp
reading(user, timestamp=timestamp)
@with_user_from(websocket, fallback_to_token=True)
async def live(timestamp, user_or_token):
match user_or_token:
case str() | None:
await websocket.send_json({'type': 'kick'})
await websocket.close(1001)
case dict() as user:
queue = asyncio.Queue()
user['websockets'][queue] = timestamp
reading(user, timestamp=timestamp)
producer = websocket_outbound(queue, user)
consumer = websocket_inbound(queue, user)
try:
await asyncio.gather(producer, consumer)
finally:
see(user)
user['websockets'].pop(queue)
producer = websocket_outbound(queue, user)
consumer = websocket_inbound(queue, user)
try:
await asyncio.gather(producer, consumer)
finally:
see(user)
user['websockets'].pop(queue)

ファイルの表示

@ -831,6 +831,11 @@ const on_websocket_message = (event) => {
ws.send(JSON.stringify(payload));
break;
case "kick":
console.log("ws kick");
window.location.reload();
break;
default:
console.log("incomprehensible websocket message", receipt);
}