diff --git a/v2realbot/config.py b/v2realbot/config.py index f1643d2..c87d4e6 100644 --- a/v2realbot/config.py +++ b/v2realbot/config.py @@ -11,6 +11,7 @@ _ml_module_loaded = False #directory for generated images and basic reports MEDIA_DIRECTORY = Path(__file__).parent.parent.parent / "media" +VBT_DOC_DIRECTORY = Path(__file__).parent.parent.parent / "vbt-doc" #directory for vbt doc RUNNER_DETAIL_DIRECTORY = Path(__file__).parent.parent.parent / "runner_detail" #location of strat.log - it is used to fetch by gui diff --git a/v2realbot/main.py b/v2realbot/main.py index 813cc79..f8e43c6 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -1,7 +1,7 @@ import os,sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) os.environ["KERAS_BACKEND"] = "jax" -from v2realbot.config import WEB_API_KEY, DATA_DIR, MEDIA_DIRECTORY, LOG_PATH, MODEL_DIR +from v2realbot.config import WEB_API_KEY, DATA_DIR, MEDIA_DIRECTORY, LOG_PATH, MODEL_DIR, VBT_DOC_DIRECTORY from alpaca.data.timeframe import TimeFrame, TimeFrameUnit from datetime import datetime from rich import print @@ -122,6 +122,22 @@ async def static_files(request: Request, path: str, authenticated: bool = Depend return FileResponse(file_path) +@app.get("/vbt-doc/{file_path:path}") +async def serve_protected_docs(file_path: str, credentials: HTTPBasicCredentials = Depends(authenticate_user)): + file_location = VBT_DOC_DIRECTORY / file_path + + if file_location.is_dir(): # If it's a directory, serve index.html + index_file = file_location / "index.html" + if index_file.exists(): + return FileResponse(index_file) + else: + raise HTTPException(status_code=404, detail="Index file not found") + elif file_location.exists(): + return FileResponse(file_location) + else: + raise HTTPException(status_code=404, detail="File not found") + + def get_current_username( credentials: Annotated[HTTPBasicCredentials, Depends(security)] ):