Merge branch 'feat/custom_schema_and_layout' of github.com:presenton/presenton into feat/custom_schema_and_layout
This commit is contained in:
commit
33299da3ac
2 changed files with 43 additions and 11 deletions
|
|
@ -134,11 +134,6 @@ async def prepare_presentation(
|
|||
|
||||
with get_sql_session() as sql_session:
|
||||
presentation = sql_session.get(PresentationModel, presentation_id)
|
||||
presentation.outlines = [each.model_dump() for each in outlines]
|
||||
presentation.title = title or presentation.title
|
||||
presentation.layout = layout.model_dump()
|
||||
sql_session.commit()
|
||||
sql_session.refresh(presentation)
|
||||
|
||||
total_slide_layouts = len(layout.slides)
|
||||
total_outlines = len(outlines)
|
||||
|
|
@ -164,6 +159,9 @@ async def prepare_presentation(
|
|||
|
||||
with get_sql_session() as sql_session:
|
||||
sql_session.add(presentation)
|
||||
presentation.outlines = [each.model_dump() for each in outlines]
|
||||
presentation.title = title or presentation.title
|
||||
presentation.set_layout(layout)
|
||||
presentation.set_structure(presentation_structure)
|
||||
sql_session.commit()
|
||||
sql_session.refresh(presentation)
|
||||
|
|
|
|||
|
|
@ -16,23 +16,57 @@ export async function POST(req: NextRequest) {
|
|||
headless: true,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu',
|
||||
'--disable-web-security',
|
||||
]
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
await page.setViewport({ width: 1280, height: 720 });
|
||||
|
||||
await page.goto(`http://localhost/pdf-maker?id=${id}`, { waitUntil: 'networkidle0', timeout: 80000 });
|
||||
|
||||
await page.waitForFunction('() => document.readyState === "complete"')
|
||||
|
||||
try {
|
||||
await page.waitForFunction(
|
||||
`
|
||||
() => {
|
||||
const allElements = document.querySelectorAll('*');
|
||||
let loadedElements = 0;
|
||||
let totalElements = allElements.length;
|
||||
|
||||
for (let el of allElements) {
|
||||
const style = window.getComputedStyle(el);
|
||||
const isVisible = style.display !== 'none' &&
|
||||
style.visibility !== 'hidden' &&
|
||||
style.opacity !== '0';
|
||||
|
||||
if (isVisible && el.offsetWidth > 0 && el.offsetHeight > 0) {
|
||||
loadedElements++;
|
||||
}
|
||||
}
|
||||
|
||||
return (loadedElements / totalElements) >= 0.95;
|
||||
}
|
||||
`,
|
||||
{ timeout: 10000 }
|
||||
);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
} catch (error) {
|
||||
console.log("Warning: Some content may not have loaded completely:", error);
|
||||
}
|
||||
|
||||
|
||||
const pdfBuffer = await page.pdf({
|
||||
printBackground: true,
|
||||
width: "1280px",
|
||||
height: "720px",
|
||||
margin: { top: 0, right: 0, bottom: 0, left: 0 }
|
||||
|
||||
printBackground: true,
|
||||
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||
});
|
||||
|
||||
browser.close();
|
||||
|
||||
const sanitizedTitle = sanitizeFilename(title);
|
||||
const destinationPath = path.join(process.env.APP_DATA_DIRECTORY!, 'exports', `${sanitizedTitle}.pdf`);
|
||||
console.log('destinationPath', destinationPath);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue