ForcePilot/src/routers/base_router.py

45 lines
990 B
Python
Raw Normal View History

2024-10-02 20:11:28 +08:00
from fastapi import APIRouter
base = APIRouter()
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
2024-10-24 13:09:59 +08:00
from fastapi import Request, Body
2025-02-27 19:35:25 +08:00
2024-10-02 20:11:28 +08:00
from src.core import HistoryManager
from src.core.startup import startup
2025-02-27 19:35:25 +08:00
from src.utils import logger
2024-10-02 20:11:28 +08:00
@base.get("/")
async def route_index():
return {"message": "You Got It!"}
@base.get("/config")
def get_config():
2024-10-02 20:11:28 +08:00
return startup.config
@base.post("/config")
2024-10-24 13:09:59 +08:00
async def update_config(key = Body(...), value = Body(...)):
startup.config[key] = value
2024-10-02 20:11:28 +08:00
startup.config.save()
return startup.config
@base.post("/restart")
async def restart():
startup.restart()
return {"message": "Restarted!"}
@base.get("/log")
def get_log():
2024-10-02 20:11:28 +08:00
from src.utils.logging_config import LOG_FILE
from collections import deque
with open(LOG_FILE, 'r') as f:
last_lines = deque(f, maxlen=1000)
log = ''.join(last_lines)
2025-02-28 00:38:59 +08:00
return {"log": log, "message": "success", "log_file": LOG_FILE}
2024-10-02 20:11:28 +08:00