fix: 修复签到成功图片不对的问题
This commit is contained in:
@@ -5,6 +5,7 @@ from fastapi import UploadFile
|
||||
import httpx
|
||||
import config
|
||||
from services.student_cache import get_student_by_token, save_student
|
||||
from exceptions.unauthorized import UnauthorizedError
|
||||
|
||||
|
||||
SEX_MAP = {
|
||||
@@ -22,8 +23,18 @@ class XBXS:
|
||||
self.token = token
|
||||
|
||||
self.client = httpx.AsyncClient(
|
||||
trust_env=False,
|
||||
base_url=config.BASE_URL,
|
||||
timeout=config.HTTPX_TIMEOUT,
|
||||
timeout=httpx.Timeout(
|
||||
connect=10.0,
|
||||
read=30.0,
|
||||
write=30.0,
|
||||
pool=10.0,
|
||||
),
|
||||
limits=httpx.Limits(
|
||||
max_connections=1, # 每个请求使用单独连接,不使用连接池
|
||||
max_keepalive_connections=1,
|
||||
),
|
||||
headers={
|
||||
"user-agent": UA,
|
||||
"accept": "*/*",
|
||||
@@ -74,6 +85,8 @@ class XBXS:
|
||||
resp = await self.client.get("/xiaobei-api/getInfo")
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
return {
|
||||
"userName": result.get("user", {}).get("userName", ""),
|
||||
"nickName": result.get("user", {}).get("nickName", ""),
|
||||
@@ -92,6 +105,9 @@ class XBXS:
|
||||
sex = result.get("data", {}).get("studentSex", "")
|
||||
sex_text = SEX_MAP.get(sex, "未知")
|
||||
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
|
||||
return {
|
||||
"id": result.get("data", {}).get("id", ""),
|
||||
"studentNumber": result.get("data", {}).get("studentNumber", ""),
|
||||
@@ -114,18 +130,30 @@ class XBXS:
|
||||
resp = await self.client.get("/xiaobei-api/student/deptId")
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
|
||||
return result
|
||||
|
||||
async def get_user_sig2(self):
|
||||
resp = await self.client.get("/xiaobei-api/trtc/genUserSig2")
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
|
||||
return result
|
||||
|
||||
async def get_know_list(self):
|
||||
resp = await self.client.get("/xiaobei-api/student/know/list")
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
|
||||
if result.get("total", 0) > 0:
|
||||
pass
|
||||
return result
|
||||
@@ -134,6 +162,10 @@ class XBXS:
|
||||
resp = await self.client.get(f"/xiaobei-api/student/know/{know}")
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
|
||||
if result.get("code") == "401":
|
||||
raise UnauthorizedError("token 已失效,请重新登录")
|
||||
|
||||
if result.get("total", 0) > 0:
|
||||
pass
|
||||
return result
|
||||
@@ -146,14 +178,20 @@ class XBXS:
|
||||
location: str,
|
||||
images: List[UploadFile],
|
||||
):
|
||||
files = {}
|
||||
files = []
|
||||
|
||||
for i, image in enumerate(images):
|
||||
# 为每个图片生成一个唯一的 UUID 文件名
|
||||
files[f"file{i}"] = (
|
||||
str(uuid4()), # 这里使用 UUID 作为文件名
|
||||
await image.read(),
|
||||
"image/jpeg", # 假设是 jpeg 格式,按需修改
|
||||
files.append(
|
||||
(
|
||||
f"file{i}",
|
||||
(
|
||||
f"{uuid4()}.jpg",
|
||||
image.file,
|
||||
image.content_type or "image/jpeg",
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
resp = await self.client.post(
|
||||
"/xiaobei-api/student/know/updateStudentKnow",
|
||||
data={
|
||||
@@ -161,7 +199,6 @@ class XBXS:
|
||||
"remark": remark,
|
||||
"knowingId": knowingID,
|
||||
"location": location,
|
||||
# "location": "106.5346788194445:29.343291015625",
|
||||
"size": len(images),
|
||||
},
|
||||
files=files,
|
||||
|
||||
Reference in New Issue
Block a user