From 1e925a38a02dbea3f06fbf40aa0c8ca6c96096d5 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Fri, 1 Apr 2022 00:52:44 +0200 Subject: [PATCH] Storing and display filename in sharing mode --- app.php | 11 ++++++++--- public/js/signature.js | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app.php b/app.php index 166bc5a..bf4e61f 100644 --- a/app.php +++ b/app.php @@ -183,8 +183,9 @@ $f3->route('POST /share', } return true; - }, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, &$svgFiles) { + }, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, $sharingFolder, &$svgFiles) { if($formFieldName == "pdf") { + file_put_contents($sharingFolder."filename.txt", $fileBaseName); return $filename; } if($formFieldName == "svg") { @@ -252,6 +253,10 @@ $f3->route('GET /signature/@hash/pdf', $files = scandir($sharingFolder); $originalFile = $sharingFolder.'/original.pdf'; $finalFile = $sharingFolder.'/'.$f3->get('PARAMS.hash').'.pdf'; + $filename = $f3->get('PARAMS.hash').'.pdf'; + if(file_exists($sharingFolder."/filename.txt")) { + $filename = file_get_contents($sharingFolder."/filename.txt"); + } $layers = []; foreach($files as $file) { if(strpos($file, 'svg.pdf') !== false) { @@ -259,14 +264,14 @@ $f3->route('GET /signature/@hash/pdf', } } if (!$layers) { - Web::instance()->send($originalFile, null, 0, TRUE, $f3->get('PARAMS.hash').'.pdf'); + Web::instance()->send($originalFile, null, 0, TRUE, $filename); } $bufferFile = str_replace('.pdf', '_tmp.pdf', $originalFile); shell_exec(sprintf("cp %s %s", $originalFile, $finalFile)); foreach($layers as $layer) { shell_exec(sprintf("pdftk %1\$s multistamp %2\$s output %3\$s && mv %3\$s %1\$s", $finalFile, $layer, $bufferFile)); } - Web::instance()->send($finalFile, null, 0, TRUE, $f3->get('PARAMS.hash').'.pdf'); + Web::instance()->send($finalFile, null, 0, TRUE, $filename); } ); diff --git a/public/js/signature.js b/public/js/signature.js index 9b2ab2d..6b426e3 100644 --- a/public/js/signature.js +++ b/public/js/signature.js @@ -968,8 +968,6 @@ var pageSignature = async function(url) { modalSigned.show(); } - let filename = url.replace('/pdf/', ''); - document.title = filename + ' - ' + document.title; document.getElementById('page-upload').classList.add('d-none'); document.getElementById('page-signature').classList.remove('d-none'); fabric.Textbox.prototype._wordJoiners = /[]/; @@ -987,6 +985,7 @@ var pageSignature = async function(url) { }); let pdfBlob = null; + let filename = url.replace('/pdf/', ''); if(hash) { var response = await fetch(url); @@ -994,9 +993,15 @@ var pageSignature = async function(url) { return; } pdfBlob = await response.blob(); + if(response.headers.get('Content-Disposition').match(/attachment; filename="/)) { + filename = response.headers.get('Content-Disposition').replace(/^[^"]*"/, "").replace(/"[^"]*$/, ""); + } } else { pdfBlob = await getPDFBlobFromCache(url); } + + document.title = filename + ' - ' + document.title; + if(!pdfBlob) { document.location = '/signature'; return;