Files
hik-push/hik_push/main.py

42 lines
884 B
Python
Raw Normal View History

2024-01-22 17:30:06 +08:00
import asyncio
import json
from typing import Dict
from redis import asyncio as aioredis
import uvicorn
2024-01-24 16:15:00 +08:00
from fastapi import FastAPI, BackgroundTasks, UploadFile
2024-01-22 17:30:06 +08:00
app = FastAPI()
async def add_stream(data: dict):
redis = await aioredis.from_url("redis://localhost", db=0)
2024-01-24 16:15:00 +08:00
await redis.lpush("event", json.dumps(data))
# await redis.xadd("hik-event", {"event": json.dumps(data)})
2024-01-22 17:30:06 +08:00
await redis.close()
2024-01-24 16:15:00 +08:00
@app.post("/upload")
async def upload_file(file: UploadFile):
print(file)
return {"message": "success"}
2024-01-22 17:30:06 +08:00
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/eventRcv")
async def event_rcv(data: dict, background_tasks: BackgroundTasks):
background_tasks.add_task(add_stream, data)
return {"data": data}
def run_app():
uvicorn.run("main:app", host="0.0.0.0", port=8000)
if __name__ == "__main__":
run_app()