boyrobot 1 year ago
parent
commit
4b8f77da75

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 *.pyc
 __pycache__/
+backend/dist/

+ 1 - 1
backend/apps/__init__.py

@@ -12,7 +12,7 @@ from apps.extensions.hook import (init_banner, init_middlewares, register_db,
 from fastapi import FastAPI
 from fastapi.routing import APIRoute
 from fastapi.staticfiles import StaticFiles
-
+from apps.websocket import socket_app
 def custom_generate_unique_id(route: APIRoute) -> str:
     return f"{route.tags[0]}-{route.name}"
 

+ 10 - 10
backend/apps/api/home.py

@@ -24,14 +24,14 @@ router = APIRouter()
 async def index():
     return {"code": 200, "message": "this is backend api"}
 
-@app.get("/{full_path:path}", include_in_schema=False)
-def spa(full_path: str):
-    dist_dir = Path(__file__).parent / "dist"
-    # TODO: hacky way to only serve index.html on root urls
-    files = [entry.name for entry in dist_dir.iterdir() if entry.is_file()]
-    if full_path in files:
-        return FileResponse(dist_dir / full_path)
-    if "." in full_path:
-        raise HTTPException(status_code=404, detail="Asset not found")
-    return HTMLResponse((dist_dir / "index.html").read_bytes())
+# @router.get("/{full_path:path}", include_in_schema=False)
+# def spa(full_path: str):
+#     dist_dir = Path(__file__).parent.parent.parent / "dist"
+#     # TODO: hacky way to only serve index.html on root urls
+#     files = [entry.name for entry in dist_dir.iterdir() if entry.is_file()]
+#     if full_path in files:
+#         return FileResponse(dist_dir / full_path)
+#     if "." in full_path:
+#         raise HTTPException(status_code=404, detail="Asset not found")
+#     return HTMLResponse((dist_dir / "index.html").read_bytes())
 

+ 1 - 1
backend/apps/models/user.py

@@ -18,7 +18,7 @@ class User(UserBase, table=True):
     """ User model """
     id: int | None = Field(default=None, primary_key=True)
     hashed_password: str
-    nick_name = Field(nullable=True, default=None, description="用户昵称")
+    nick_name:str = Field(nullable=True,default=None, description="用户昵称")
     sex: str = Field(nullable=True, default=None, description="用户性别")
     identity_card: str = Field(nullable=True, default=None, description="用户身份证")
     phone: str | None = Field(nullable=True, default=None, description="用户电话")

+ 3 - 0
backend/apps/utils/__init__.py

@@ -0,0 +1,3 @@
+# from .str_util import *
+# from .log_util import *
+# from mail_util import *

+ 16 - 0
backend/apps/utils/str_util.py

@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+"""
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2024/04/14
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   str util
+"""
+
+class StrUtil(object):
+    """ str util """
+    
+    @staticmethod
+    def round_float():
+        pass
+    

+ 5 - 5
backend/apps/websocket/server.py

@@ -2,7 +2,7 @@
 import socketio
 import psutil
 import threading
-from app.extensions.utils import round_float
+# from app.extensions.utils import round_float
 
 lock = threading.Lock()
 
@@ -75,14 +75,14 @@ class ServerNamespace(socketio.AsyncNamespace):
             'used': psutil.cpu_percent(interval=0.1),  # cpu使用率
             'pids': len(psutil.pids()),  # 进程数
             'cpu_freq': psutil.cpu_freq().current,  # CPU频率
-            'boot_time': round_float(psutil.boot_time() / (60 * 60 * 60 * 24)),  # 系统启动时间
+            # 'boot_time': round_float(psutil.boot_time() / (60 * 60 * 60 * 24)),  # 系统启动时间
         }
         sys_info["cpu_info"] = cpu_info
         memory_info = psutil.virtual_memory()
         memory_info = {
-            "total": round_float(memory_info.total / (1024 * 1024 * 1024)),
-            "used": round_float(memory_info.used / (1024 * 1024 * 1024)),
-            "free": round_float(memory_info.free / (1024 * 1024 * 1024)),
+            # "total": round_float(memory_info.total / (1024 * 1024 * 1024)),
+            # "used": round_float(memory_info.used / (1024 * 1024 * 1024)),
+            # "free": round_float(memory_info.free / (1024 * 1024 * 1024)),
             "percent": memory_info.percent,
         }
         sys_info["memory_info"] = memory_info

+ 1 - 1
backend/main.py

@@ -9,4 +9,4 @@
 from app import app
 if __name__ == "__main__":
     import uvicorn
-    uvicorn.run(app, host="0.0.0.0", port=8080, reload=True, workers=1, log_config="uvicorn_loggin_config.json")
+    uvicorn.run(app, host="0.0.0.0", port=8080,)

+ 1 - 0
backend/requirements.txt

@@ -60,3 +60,4 @@ uvicorn[standard]==0.24.0.post1 ; python_version >= "3.10" and python_version <
 uvloop==0.19.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.10" and python_version < "4.0"
 watchfiles==0.21.0 ; python_version >= "3.10" and python_version < "4.0"
 websockets==12.0 ; python_version >= "3.10" and python_version < "4.0"
+python-socketio==5.11.2