From 169693e4c73f255cab5dab36b502b3021ac8d671 Mon Sep 17 00:00:00 2001 From: Paul Eipper Date: Wed, 5 Oct 2022 15:36:02 -0300 Subject: [PATCH] Fix image url expiration on long documents Generate the page url on-demand to avoid link expiration. --- src/DocSendDownloader.js | 8 +------- src/GeneratePDF.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DocSendDownloader.js b/src/DocSendDownloader.js index a1a677b..b482dd2 100644 --- a/src/DocSendDownloader.js +++ b/src/DocSendDownloader.js @@ -19,13 +19,7 @@ let userIsAuthenticated = () => { let getSlideImageUrls = async () => { for(let i=1; i<=numSlides; i++) { let url = metadataEndpoint + String(i); - await fetch(url) - .then((response) => { - return response.json(); - }) - .then((data) => { - slideImageUrls.push(data.imageUrl); - }) + slideImageUrls.push(url); } } diff --git a/src/GeneratePDF.js b/src/GeneratePDF.js index 9e60ffb..04a55a1 100644 --- a/src/GeneratePDF.js +++ b/src/GeneratePDF.js @@ -22,12 +22,18 @@ const getImageAsBlob = async (url) => const addSlidesToPDF = async (imageUrls) =>{ for (let i=0; i { + await fetch(imageUrls[i]) + .then((response) => { + return response.json(); + }) + .then((data) => { + return getImageAsBlob(data.imageUrl); + }) + .then((data) => { const img = doc.openImage(data); doc.addPage({size: [img.width, img.height]}); doc.image(img, 0, 0); - - }) + }) } }