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.
このコミットが含まれているのは:
コミット
4a76fb023e
|
@ -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);
|
||||
}
|
||||
|
|
読み込み中…
新しいイシューから参照