Chemins relatifs pour les formats

This commit is contained in:
François Pelletier 2024-11-11 01:11:33 -05:00
parent dda4bc870d
commit 4734b5b7f0
4 changed files with 79 additions and 39 deletions

View file

@ -15,7 +15,7 @@ router = APIRouter()
@router.get("/styles/")
async def get_styles(current_user: Annotated[User, Depends(get_current_active_user)]):
styles = Styles(styles=list_dir("{os.getcwd()}/styles"))
styles = Styles(styles=list_dir(f"{os.getcwd()}/styles"))
return styles
@router.get("/formats/{style}/")

View file

@ -60,7 +60,7 @@ async def generer(specs: DocumentSpecs, background_tasks: BackgroundTasks, curre
pdf_file_path = f"{output_dir}/{base_name}.pdf"
markdown_file_path = f"{output_dir}/{base_name}.md"
latex_file_path = f"{output_dir}/{base_name}.tex"
images_path = f"{output_dir}/{base_name}_images"
images_path = f"{output_dir}/images"
video_file_path = f"{output_dir}/{base_name}.mp4"
try:
@ -107,13 +107,23 @@ async def generer(specs: DocumentSpecs, background_tasks: BackgroundTasks, curre
# Generate MP4 video
logger.info("Generating MP4 video...")
convert_video(images_path=images_path,
output_path=video_file_path,
width=specs.paperwidth,
height=specs.paperheight,
fps=specs.fps,
stilltime=specs.stilltime)
logger.info(f"MP4 video generated: {video_file_path}")
try:
success = convert_video(
images_path=images_path,
output_path=video_file_path,
width=specs.paperwidth,
height=specs.paperheight,
fps=specs.fps,
stilltime=specs.stilltime
)
if success:
logger.info(f"MP4 video generated: {video_file_path}")
else:
logger.error(f"Failed to generate MP4 video: {video_file_path}")
raise Exception("Video generation failed")
except Exception as e:
logger.exception(f"Error during video generation: {str(e)}")
raise HTTPException(status_code=500, detail=f"Video generation failed: {str(e)}")
# Create ZIP file
zip_file_path = f"{output_dir}/{base_name}.zip"

View file

@ -12,14 +12,14 @@ router = APIRouter()
@router.get("/")
async def get_images(current_user: Annotated[User, Depends(get_current_active_user)]):
# list all files in resources/images
files = [f for f in os.listdir("../resources/images") if os.path.isfile(os.path.join("../resources/images", f))]
files = [f for f in os.listdir(f"{os.getcwd()}/resources/images") if os.path.isfile(os.path.join(f"{os.getcwd()}/resources/images", f))]
# sort the files
files.sort()
return {"images": files}
@router.get("/{nom_image}")
async def get_image(nom_image: str, current_user: Annotated[User, Depends(get_current_active_user)]):
return FileResponse(f"./resources/images/{nom_image}")
return FileResponse(f"{os.getcwd()}/resources/images/{nom_image}")
@router.post("/")
async def ajouter_image(file: UploadFile, current_user: Annotated[User, Depends(get_current_active_user)]):