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
|
from anonstream.routes.wrappers import with_user_from
|
||||||
|
|
||||||
@current_app.websocket('/live')
|
@current_app.websocket('/live')
|
||||||
@with_user_from(websocket)
|
@with_user_from(websocket, fallback_to_token=True)
|
||||||
async def live(timestamp, user):
|
async def live(timestamp, user_or_token):
|
||||||
queue = asyncio.Queue()
|
match user_or_token:
|
||||||
user['websockets'][queue] = timestamp
|
case str() | None:
|
||||||
reading(user, timestamp=timestamp)
|
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)
|
producer = websocket_outbound(queue, user)
|
||||||
consumer = websocket_inbound(queue, user)
|
consumer = websocket_inbound(queue, user)
|
||||||
try:
|
try:
|
||||||
await asyncio.gather(producer, consumer)
|
await asyncio.gather(producer, consumer)
|
||||||
finally:
|
finally:
|
||||||
see(user)
|
see(user)
|
||||||
user['websockets'].pop(queue)
|
user['websockets'].pop(queue)
|
||||||
|
|
|
@ -831,6 +831,11 @@ const on_websocket_message = (event) => {
|
||||||
ws.send(JSON.stringify(payload));
|
ws.send(JSON.stringify(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "kick":
|
||||||
|
console.log("ws kick");
|
||||||
|
window.location.reload();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log("incomprehensible websocket message", receipt);
|
console.log("incomprehensible websocket message", receipt);
|
||||||
}
|
}
|
||||||
|
|
読み込み中…
新しいイシューから参照