Chemins relatifs pour les formats

This commit is contained in:
François Pelletier 2024-11-11 00:21:26 -05:00
parent 3ff972a018
commit dda4bc870d

View file

@ -1,5 +1,6 @@
import json
import logging
import os
from typing import Annotated
from fastapi import APIRouter, Depends
@ -14,18 +15,18 @@ router = APIRouter()
@router.get("/styles/")
async def get_styles(current_user: Annotated[User, Depends(get_current_active_user)]):
styles = Styles(styles=list_dir("../styles"))
styles = Styles(styles=list_dir("{os.getcwd()}/styles"))
return styles
@router.get("/formats/{style}/")
async def get_formats(style: str, current_user: Annotated[User, Depends(get_current_active_user)]):
formats = Formats(formats=list_dir(f"./styles/{style}/"))
formats = Formats(formats=list_dir(f"{os.getcwd()}/styles/{style}/"))
return formats
@router.get("/format_parameters/{style}/{format}/")
async def get_format_parameters(style: str, format: str, current_user: Annotated[User, Depends(get_current_active_user)]):
# open styles/format_parameters.json as a dictionary
with open(f"./styles/{style}/format_parameters.json", "r") as f:
with open(f"{os.getcwd()}/styles/{style}/format_parameters.json", "r") as f:
format_data = json.load(f).get(format)
logging.info(str(format_data))
# load data from format_data into the FormatParameters object