Changes: use presentation title as name on download

This commit is contained in:
sauravniraula 2025-05-12 00:56:23 +05:45
parent 96f60288f5
commit becf63d660
No known key found for this signature in database
GPG key ID: 60FCC1B5A5E83326
3 changed files with 24 additions and 2 deletions

View file

@ -9,8 +9,10 @@ from api.routers.presentation.models import (
ExportAsRequest,
PresentationAndPath,
)
from api.services.database import get_sql_session
from api.services.instances import temp_file_service
from api.services.logging import LoggingService
from api.sql_models import PresentationSqlModel
from api.utils import get_presentation_dir
from image_processor.image_from_pptx import get_pdf_from_pptx
from ppt_generator.pptx_presentation_creator import PptxPresentationCreator
@ -37,12 +39,22 @@ class ExportAsPDFHandler(FetchPresentationAssetsMixin):
await self.fetch_presentation_assets()
ppt_path = os.path.join(self.presentation_dir, "presentation.pptx")
with get_sql_session() as sql_session:
presentation = sql_session.get(
PresentationSqlModel, self.data.presentation_id
)
ppt_path = os.path.join(
self.presentation_dir,
f"{presentation.title.replace('/', '_').replace(' ', '_')}.pptx",
)
ppt_creator = PptxPresentationCreator(self.data.pptx_model, self.temp_dir)
ppt_creator.create_ppt()
ppt_creator.save(ppt_path)
print(ppt_path)
pdf_path = get_pdf_from_pptx(ppt_path, self.presentation_dir)
response = PresentationAndPath(

View file

@ -37,7 +37,15 @@ class ExportAsPptxHandler(FetchPresentationAssetsMixin):
await self.fetch_presentation_assets()
ppt_path = os.path.join(self.presentation_dir, "presentation.pptx")
with get_sql_session() as sql_session:
presentation = sql_session.get(
PresentationSqlModel, self.data.presentation_id
)
ppt_path = os.path.join(
self.presentation_dir,
f"{presentation.title.replace('/', '_').replace(' ', '_')}.pptx",
)
ppt_creator = PptxPresentationCreator(self.data.pptx_model, self.temp_dir)
ppt_creator.create_ppt()
ppt_creator.save(ppt_path)

View file

@ -8,6 +8,7 @@ from image_processor.utils import get_page_images_from_pdf
def get_pdf_from_pptx(pptx_path: str, temp_dir: str) -> str:
base_name = os.path.splitext(os.path.basename(pptx_path))[0]
print(base_name)
subprocess.run(
f"{os.getenv('LIBREOFFICE')} --headless --invisible --convert-to pdf {pptx_path} --outdir {temp_dir}",
@ -17,6 +18,7 @@ def get_pdf_from_pptx(pptx_path: str, temp_dir: str) -> str:
pdf_filename = f"{base_name}.pdf"
pdf_path = os.path.join(temp_dir, pdf_filename)
print(pdf_path)
return pdf_path