diff --git a/backend/server.js b/backend/server.js index d98f0b2..2fb23c1 100644 --- a/backend/server.js +++ b/backend/server.js @@ -176,8 +176,12 @@ async function startServer() { console.log('Received files:', req.files); const { typ, titel, inhalt, strophen, copyright } = req.body; - const notenbild = req.files && req.files['notenbild'] ? req.files['notenbild'][0].path : null; - const notenbildMitText = req.files && req.files['notenbildMitText'] ? req.files['notenbildMitText'][0].path : null; + const notenbild = req.files && req.files['notenbild'] + ? path.join('/uploads', path.relative(path.join(__dirname, 'uploads'), req.files['notenbild'][0].path)) + : null; + const notenbildMitText = req.files && req.files['notenbildMitText'] + ? path.join('/uploads', path.relative(path.join(__dirname, 'uploads'), req.files['notenbildMitText'][0].path)) + : null; console.log('Prepared data:', { typ, titel, inhalt, strophen, notenbild, notenbildMitText, copyright }); @@ -231,10 +235,10 @@ async function startServer() { let notenbildMitText = existingObjekt[0].notenbildMitText; if (req.files && req.files['notenbild']) { - notenbild = req.files['notenbild'][0].path; + notenbild = path.join('/uploads', path.relative(path.join(__dirname, 'uploads'), req.files['notenbild'][0].path)); } if (req.files && req.files['notenbildMitText']) { - notenbildMitText = req.files['notenbildMitText'][0].path; + notenbildMitText = path.join('/uploads', path.relative(path.join(__dirname, 'uploads'), req.files['notenbildMitText'][0].path)); } const query = 'UPDATE objekte SET typ = ?, titel = ?, inhalt = ?, strophen = ?, notenbild = ?, notenbildMitText = ?, copyright = ? WHERE id = ?'; diff --git a/frontend/script.js b/frontend/script.js index bb7722b..0e90f25 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -1871,7 +1871,16 @@ async function generatePDF(format) { const logoResponse = await fetch(logoUrl); if (!logoResponse.ok) throw new Error(`HTTP error! Status: ${logoResponse.status}`); const logoArrayBuffer = await logoResponse.arrayBuffer(); - logoImage = await doc.embedPng(logoArrayBuffer); + + const logoType = getImageType(logoArrayBuffer); + + if (logoType === 'png') { + logoImage = await doc.embedPng(logoArrayBuffer); + } else if (logoType === 'jpeg') { + logoImage = await doc.embedJpg(logoArrayBuffer); + } else { + throw new Error('Unsupported logo image type'); + } console.log("Church logo embedded successfully"); } catch (error) { @@ -1881,6 +1890,20 @@ async function generatePDF(format) { console.log("No church logo path found in global config"); } + function getImageType(arrayBuffer) { + const uint8Array = new Uint8Array(arrayBuffer); + const pngSignature = [137, 80, 78, 71, 13, 10, 26, 10]; + const jpegSignature = [255, 216, 255]; + + if (pngSignature.every((byte, index) => uint8Array[index] === byte)) { + return 'png'; + } else if (jpegSignature.every((byte, index) => uint8Array[index] === byte)) { + return 'jpeg'; + } else { + return 'unknown'; + } + } + function addLogoToPage(page) { if (logoImage) { const pageWidth = page.getWidth(); @@ -2015,7 +2038,16 @@ async function generatePDF(format) { try { const response = await fetch(imgSrc); const imgArrayBuffer = await response.arrayBuffer(); - let img = await doc.embedPng(imgArrayBuffer); + const imgType = getImageType(imgArrayBuffer); + + let img; + if (imgType === 'png') { + img = await doc.embedPng(imgArrayBuffer); + } else if (imgType === 'jpeg') { + img = await doc.embedJpg(imgArrayBuffer); + } else { + throw new Error('Unsupported image type'); + } const scaledDims = img.scale(imgWidth / img.width); @@ -2033,6 +2065,20 @@ async function generatePDF(format) { } } + function getImageType(arrayBuffer) { + const uint8Array = new Uint8Array(arrayBuffer); + const pngSignature = [137, 80, 78, 71, 13, 10, 26, 10]; + const jpegSignature = [255, 216, 255]; + + if (pngSignature.every((byte, index) => uint8Array[index] === byte)) { + return 'png'; + } else if (jpegSignature.every((byte, index) => uint8Array[index] === byte)) { + return 'jpeg'; + } else { + return 'unknown'; + } + } + async function drawIcon(iconName, x, y, size) { console.log("Drawing icon:", { iconName, x, y, size }); const iconPaths = {