mirror of
https://github.com/Sosokker/HomieCare.git
synced 2025-12-20 02:14:05 +01:00
Add FastAPI app and video routers
This commit is contained in:
parent
83ab4c56b0
commit
d0d27fca8d
@ -0,0 +1,22 @@
|
|||||||
|
import uvicorn
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from routers import video
|
||||||
|
|
||||||
|
app = FastAPI(
|
||||||
|
title="Dispatch",
|
||||||
|
description="Hello Stranger.",
|
||||||
|
root_path="/api/v1",
|
||||||
|
docs_url=None,
|
||||||
|
openapi_url="/docs/openapi.json",
|
||||||
|
redoc_url="/docs"
|
||||||
|
)
|
||||||
|
|
||||||
|
app.include_router(video.router, prefix="/camera")
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def read_root():
|
||||||
|
return {"Hello": "World"}
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
uvicorn.run(app, host="127.0.0.1", port=8000)
|
||||||
0
StreamServer/src/routers/__init__.py
Normal file
0
StreamServer/src/routers/__init__.py
Normal file
29
StreamServer/src/routers/video.py
Normal file
29
StreamServer/src/routers/video.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from scheme import Camera
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
cameras: List[Camera] = []
|
||||||
|
|
||||||
|
@router.post("/add_camera", response_model=dict)
|
||||||
|
async def add_camera(rtsp_link: str):
|
||||||
|
if rtsp_link:
|
||||||
|
camera = Camera(rtsp_link=rtsp_link)
|
||||||
|
cameras.append(camera)
|
||||||
|
return {"message": "Camera added successfully"}
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=400, detail="Invalid RTSP link")
|
||||||
|
|
||||||
|
@router.get("/stream_video")
|
||||||
|
async def stream_video():
|
||||||
|
# TODO: Implement video streaming
|
||||||
|
return {"message": "Camera disconnected successfully"}
|
||||||
|
|
||||||
|
@router.delete("/disconnect_camera/{camera_id}", response_model=dict)
|
||||||
|
async def disconnect_camera(camera_id: int):
|
||||||
|
if 0 <= camera_id < len(cameras):
|
||||||
|
del cameras[camera_id]
|
||||||
|
return {"message": "Camera disconnected successfully"}
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=404, detail="Camera not found")
|
||||||
Loading…
Reference in New Issue
Block a user