mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-05-24 14:33:26 +00:00
Настройки через app
This commit is contained in:
parent
52b1c6b365
commit
ed9a93a04f
|
@ -4,7 +4,6 @@ import logging
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
import lib.app.app as app_module
|
import lib.app.app as app_module
|
||||||
import lib.app.settings as app_settings
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -12,11 +11,11 @@ logger = logging.getLogger(__name__)
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
app_instance = app_module.Application()
|
app_instance = app_module.Application()
|
||||||
|
|
||||||
app = app_instance.create_app()
|
app = app_instance.create_app()
|
||||||
settings = app_settings.get_settings()
|
settings = app_instance.settings
|
||||||
|
|
||||||
logger.info("Starting FastAPI application")
|
logger.info("Starting FastAPI application")
|
||||||
|
|
||||||
config = uvicorn.Config(app=app, host=settings.api.host, port=settings.api.port, lifespan="on", reload=True)
|
config = uvicorn.Config(app=app, host=settings.api.host, port=settings.api.port, lifespan="on", reload=True)
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,14 @@ from jose import JWTError, jwt
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
|
|
||||||
import lib.api.schemas as app_schemas
|
import lib.api.schemas as app_schemas
|
||||||
import lib.app.settings as app_settings
|
|
||||||
|
|
||||||
settings = app_settings.get_settings()
|
|
||||||
|
|
||||||
|
|
||||||
def get_token_data(
|
def get_token_data(
|
||||||
|
request: fastapi.Request,
|
||||||
authorization: fastapi.security.HTTPAuthorizationCredentials = fastapi.Security(fastapi.security.HTTPBearer()),
|
authorization: fastapi.security.HTTPAuthorizationCredentials = fastapi.Security(fastapi.security.HTTPBearer()),
|
||||||
) -> app_schemas.entity.Token:
|
) -> app_schemas.entity.Token:
|
||||||
token = authorization.credentials
|
token = authorization.credentials
|
||||||
|
settings = request.app.state.settings
|
||||||
try:
|
try:
|
||||||
secret_key = settings.jwt_secret_key
|
secret_key = settings.jwt_secret_key
|
||||||
payload = jwt.decode(token, secret_key, algorithms=["HS256"])
|
payload = jwt.decode(token, secret_key, algorithms=["HS256"])
|
||||||
|
|
|
@ -69,6 +69,8 @@ class Application:
|
||||||
async def shutdown_event():
|
async def shutdown_event():
|
||||||
self.logger.info("Shutting down server")
|
self.logger.info("Shutting down server")
|
||||||
|
|
||||||
|
app.state.settings = self.settings
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user