From f41ca9e5dc78baa5a50c32ed05c05876266c6dd4 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 12 十月 2024 14:24:18 +0800 Subject: [PATCH] 对话的token从url传 --- app/config/config.py | 1 - restart.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ app/api/__init__.py | 7 +++---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/api/__init__.py b/app/api/__init__.py index 5ddd5aa..51c31da 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -48,11 +48,10 @@ async def get_current_user_websocket(websocket: WebSocket): - auth_header = websocket.headers.get('Authorization') - if auth_header is None or not auth_header.startswith('Bearer '): + token = websocket.query_params.get('token') + if token is None: await websocket.close(code=1008) raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION) - token = auth_header[len('Bearer '):] try: payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) username: str = payload.get("sub") @@ -67,4 +66,4 @@ except jwt.PyJWTError as e: print(e) await websocket.close(code=1008) - raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION) + raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION) \ No newline at end of file diff --git a/app/config/config.py b/app/config/config.py index 0833ef2..10c3cb8 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -1,4 +1,3 @@ -import os from pathlib import Path import yaml diff --git a/restart.sh b/restart.sh new file mode 100644 index 0000000..0c49e3b --- /dev/null +++ b/restart.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# 瀹氫箟鍙橀噺 +VENV_PATH="./venv" # 铏氭嫙鐜璺緞 +APP_NAME="main:app" +HOST="0.0.0.0" +PORT="9201" +UVICORN_CMD="uvicorn $APP_NAME --host $HOST --port $PORT" + +# 婵�娲昏櫄鎷熺幆澧� +source $VENV_PATH/bin/activate + +# 鍋滄鐜版湁杩涚▼ +echo "Stopping existing processes..." +PIDS=$(pgrep -f "$UVICORN_CMD") + +if [ -z "$PIDS" ]; then + echo "No running processes found." +else + for PID in $PIDS; do + echo "Terminating process $PID..." + kill -15 $PID + sleep 1 # 绛夊緟1绉掞紝纭繚杩涚▼鏈夋椂闂翠紭闆呭叧闂� + if kill -0 $PID > /dev/null 2>&1; then + echo "Process $PID is still running, sending SIGKILL..." + kill -9 $PID + fi + done +fi + +# 鍚姩鏂拌繘绋� +echo "Starting new process..." +$UVICORN_CMD > server.log 2>&1 & +NEW_PID=$! +echo "New process started with PID $NEW_PID." + +# 鍙�夛細妫�鏌ユ柊杩涚▼鏄惁鎴愬姛鍚姩 +sleep 2 # 绛夊緟2绉掞紝纭繚鏂拌繘绋嬫湁瓒冲鐨勬椂闂村惎鍔� +if kill -0 $NEW_PID > /dev/null 2>&1; then + echo "New process with PID $NEW_PID is running." +else + echo "Failed to start the new process." +fi \ No newline at end of file -- Gitblit v1.8.0