From b3c7c186a8606f184e6f50a1d9d3338de0dbf220 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 31 Mar 2022 11:08:46 +0200 Subject: [PATCH 1/3] Form and button to share pdf --- templates/signature.html.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/templates/signature.html.php b/templates/signature.html.php index d5f34e6..488fd17 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -70,14 +70,21 @@
- -
- - -
- -
-
+
+
+ +
+ +
+
+
+ + +
+ +
+
+
From a41155c9509501f65a06445d264fd3337f7462c5 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 31 Mar 2022 11:46:03 +0200 Subject: [PATCH 2/3] Share upload file original and redirect to a new route with a hash --- app.php | 39 +++++++++++++++++++++++++++++++++++++++ public/js/signature.js | 1 + 2 files changed, 40 insertions(+) diff --git a/app.php b/app.php index 1b054cf..53c6298 100644 --- a/app.php +++ b/app.php @@ -53,6 +53,18 @@ $f3->route('GET /signature', echo View::instance()->render('signature.html.php'); } ); + +$f3->route('GET /signature/@hash', + function($f3, $param) { + $f3->set('hash', $param['hash']); + + $f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize'))))); + $f3->set('maxPage', ini_get('max_file_uploads') - 1); + + echo View::instance()->render('signature.html.php'); + } +); + $f3->route('GET /organization', function($f3) { $f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize'))))); @@ -151,6 +163,33 @@ $f3->route('POST /sign', } ); +$f3->route('POST /share', + function($f3) { + $hash = substr(hash('sha512', uniqid().rand()), 0, 20); + $sharingFolder = $f3->get('STORAGE').$hash."/"; + $f3->set('UPLOADS', $sharingFolder); + mkdir($sharingFolder); + $filename = "original.pdf"; + + $files = Web::instance()->receive(function($file,$formFieldName){ + if(strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) { + $f3->error(403); + } + + return true; + }, false, function($fileBaseName, $formFieldName) use ($filename) { + + return $filename; + }); + + if(!count($files)) { + $f3->error(403); + } + $f3->reroute('/signature/'.$hash); + } + +); + $f3->route('POST /organize', function($f3) { $filename = null; diff --git a/public/js/signature.js b/public/js/signature.js index f04f321..262ee0e 100644 --- a/public/js/signature.js +++ b/public/js/signature.js @@ -28,6 +28,7 @@ var loadPDF = async function(pdfBlob, filename) { type: 'application/pdf' })); document.getElementById('input_pdf').files = dataTransfer.files; + document.getElementById('input_pdf_share').files = dataTransfer.files; var loadingTask = pdfjsLib.getDocument(url); loadingTask.promise.then(function(pdf) { From b6dad1dcf50a4eae3be746ce1062d8fd5307a8a7 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 31 Mar 2022 11:53:55 +0200 Subject: [PATCH 3/3] Loading pdf from hash --- public/js/signature.js | 15 ++++++++++++++- templates/signature.html.php | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/public/js/signature.js b/public/js/signature.js index 262ee0e..d5fccb6 100644 --- a/public/js/signature.js +++ b/public/js/signature.js @@ -947,7 +947,15 @@ var pageSignature = async function(url) { fontCaveat = font; }); - let pdfBlob = await getPDFBlobFromCache(url); + if(hash) { + var response = await fetch(url); + if(response.status != 200) { + return; + } + let pdfBlob = await response.blob(); + } else { + let pdfBlob = await getPDFBlobFromCache(url); + } if(!pdfBlob) { document.location = '/signature'; return; @@ -962,6 +970,11 @@ var pageSignature = async function(url) { }; (function () { + if(hash) { + pageSignature('/signature/'+hash+'/pdf'); + return; + } + if(window.location.hash && window.location.hash.match(/^\#http/)) { let hashUrl = window.location.hash.replace(/^\#/, ''); pageUpload(); diff --git a/templates/signature.html.php b/templates/signature.html.php index 488fd17..b8d61a0 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -157,6 +157,10 @@