fix(pptx): pre-fetch images server-side before passing to pptxgenjs
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 3s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 3s
pptxgenjs sur Node.js ne peut pas charger les URLs qui nécessitent une auth ou des cookies. On fetch maintenant chaque imageUrl côté serveur et on la convertit en data URI base64 avant d'appeler buildPresentation. Si le fetch échoue (timeout 8s, 4xx/5xx), l'imageUrl est supprimée et le placeholder texte s'affiche à la place. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1111,6 +1111,26 @@ RULES:
|
||||
|
||||
if (spec.slides.length === 0) return { success: false, error: 'No slides provided' }
|
||||
|
||||
// Pre-fetch all image URLs server-side and convert to base64 data URIs.
|
||||
// pptxgenjs on Node.js cannot reliably fetch authenticated or relative URLs,
|
||||
// so we do it here where we have full server context.
|
||||
for (const slide of spec.slides) {
|
||||
if (!slide.imageUrl || slide.imageUrl.startsWith('data:')) continue
|
||||
try {
|
||||
const res = await fetch(slide.imageUrl, { signal: AbortSignal.timeout(8000) })
|
||||
if (res.ok) {
|
||||
const buf = await res.arrayBuffer()
|
||||
const mime = res.headers.get('content-type') || 'image/png'
|
||||
const b64 = Buffer.from(buf).toString('base64')
|
||||
slide.imageUrl = `data:${mime};base64,${b64}`
|
||||
} else {
|
||||
slide.imageUrl = undefined // failed: show placeholder text
|
||||
}
|
||||
} catch {
|
||||
slide.imageUrl = undefined
|
||||
}
|
||||
}
|
||||
|
||||
const pptx = buildPresentation(spec)
|
||||
const base64 = await pptx.write({ outputType: 'base64' }) as string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user