mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-14 15:15:22 +03:00
POC: Converted two more endpoints to FastAPI
This commit is contained in:
parent
773d211017
commit
93b88e5d08
@ -10,7 +10,7 @@ from functools import reduce
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from fastapi import APIRouter, Path
|
from fastapi import APIRouter, Path, Request, Response
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from flask import Blueprint, Flask, current_app, jsonify, make_response, request
|
from flask import Blueprint, Flask, current_app, jsonify, make_response, request
|
||||||
@ -109,15 +109,15 @@ def create_app(
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/")
|
@router.get("/", tags=[Tags.app])
|
||||||
def is_healthy():
|
def is_healthy():
|
||||||
return "Frigate is running. Alive and healthy!"
|
return "Frigate is running. Alive and healthy!"
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/config/schema.json")
|
@router.get("/config/schema.json", tags=[Tags.app])
|
||||||
def config_schema():
|
def config_schema(request: Request):
|
||||||
return current_app.response_class(
|
return Response(
|
||||||
current_app.frigate_config.schema_json(), mimetype="application/json"
|
content=request.app.frigate_config.schema_json(), media_type="application/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ from enum import Enum
|
|||||||
|
|
||||||
|
|
||||||
class Tags(Enum):
|
class Tags(Enum):
|
||||||
|
app = "App"
|
||||||
preview = "Preview"
|
preview = "Preview"
|
||||||
logs = "Logs"
|
logs = "Logs"
|
||||||
media = "Media"
|
media = "Media"
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import logging
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from frigate.api import app as main_app
|
from frigate.api import app as main_app
|
||||||
from frigate.api.defs.tags import Tags
|
|
||||||
from frigate.api import preview
|
from frigate.api import preview
|
||||||
from frigate.plus import PlusApi
|
from frigate.plus import PlusApi
|
||||||
from frigate.ptz.onvif import OnvifController
|
from frigate.ptz.onvif import OnvifController
|
||||||
@ -13,23 +12,6 @@ from frigate.storage import StorageMaintainer
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# https://fastapi.tiangolo.com/tutorial/metadata/#use-your-tags
|
|
||||||
tags_metadata = [
|
|
||||||
{
|
|
||||||
"name": Tags.preview,
|
|
||||||
"description": "Preview routes",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": Tags.logs,
|
|
||||||
"description": "Logs routes",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": Tags.media,
|
|
||||||
"description": "Media routes",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def create_fastapi_app(
|
def create_fastapi_app(
|
||||||
frigate_config,
|
frigate_config,
|
||||||
detected_frames_processor,
|
detected_frames_processor,
|
||||||
@ -39,7 +21,7 @@ def create_fastapi_app(
|
|||||||
stats_emitter: StatsEmitter,
|
stats_emitter: StatsEmitter,
|
||||||
):
|
):
|
||||||
logger.info("Starting FastAPI app")
|
logger.info("Starting FastAPI app")
|
||||||
app = FastAPI(debug=False, tags_metadata=tags_metadata)
|
app = FastAPI(debug=False)
|
||||||
# Routes
|
# Routes
|
||||||
app.include_router(main_app.router)
|
app.include_router(main_app.router)
|
||||||
app.include_router(preview.router)
|
app.include_router(preview.router)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user