summaryrefslogtreecommitdiff
path: root/ATRI/plugins/console/driver/depends.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2023-03-10 01:12:02 +0800
committerKyomotoi <[email protected]>2023-03-10 01:12:02 +0800
commit7c79376f40e1a23b2bc82b8b89957b6f42a73b14 (patch)
tree0077f2f1e079573ed7d66c2bcadf873d3460a182 /ATRI/plugins/console/driver/depends.py
parent33178079549121d60a9703ad6bf584aa71f5481b (diff)
downloadATRI-7c79376f40e1a23b2bc82b8b89957b6f42a73b14.tar.gz
ATRI-7c79376f40e1a23b2bc82b8b89957b6f42a73b14.tar.bz2
ATRI-7c79376f40e1a23b2bc82b8b89957b6f42a73b14.zip
♻️ 重构 console, 使之代码可读性提高
Diffstat (limited to 'ATRI/plugins/console/driver/depends.py')
-rw-r--r--ATRI/plugins/console/driver/depends.py38
1 files changed, 0 insertions, 38 deletions
diff --git a/ATRI/plugins/console/driver/depends.py b/ATRI/plugins/console/driver/depends.py
deleted file mode 100644
index 8205f44..0000000
--- a/ATRI/plugins/console/driver/depends.py
+++ /dev/null
@@ -1,38 +0,0 @@
-from typing import Union
-from datetime import datetime
-
-from fastapi import Query, HTTPException, status
-from starlette.websockets import WebSocket
-
-from ..data_source import AuthDealer
-
-
-def http_author(token: Union[str, None] = Query(default=None)):
- data = AuthDealer.get()
- if data is None:
- raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="验证信息不存在")
-
- now_time = datetime.now().timestamp()
- if token != data.token:
- raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="密钥不匹配, 请检查")
- elif now_time > data.dead_time:
- raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="密钥已过期")
- else:
- return token
-
-
-async def websocket_author(
- websocket: WebSocket, token: Union[str, None] = Query(default=None)
-):
- data = AuthDealer.get()
- if not data:
- await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
- return
-
- now_time = datetime.now().timestamp()
- if token != data.token:
- await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
- elif now_time > data.dead_time:
- await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
- else:
- return token