diff --git a/app.php b/app.php index 208952c..e92cc92 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..d5fccb6 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) { @@ -946,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; @@ -961,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 d5f34e6..b8d61a0 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -70,14 +70,21 @@
- -
- - -
- -
-
+
+
+ +
+ +
+
+
+ + +
+ +
+
+
@@ -150,6 +157,10 @@