diff --git a/app.php b/app.php index 7197a48..18cc252 100644 --- a/app.php +++ b/app.php @@ -140,8 +140,8 @@ $f3->route('POST /sign', $f3->route('POST /share', function($f3) { $hash = substr(hash('sha512', uniqid().rand()), 0, 20); - $sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash."/"; - $f3->set('UPLOADS', $sharingFolder); + $sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash; + $f3->set('UPLOADS', $sharingFolder."/"); if (!is_dir($f3->get('PDF_STORAGE_PATH'))) { $f3->error(500, 'Sharing folder doesn\'t exist'); } @@ -149,6 +149,9 @@ $f3->route('POST /share', $f3->error(500, 'Sharing folder is not writable'); } mkdir($sharingFolder); + $expireFile = $sharingFolder.".expire"; + file_put_contents($expireFile, $f3->get('POST.duration')); + touch($expireFile, date_format(date_modify(date_create(), file_get_contents($expireFile)), 'U')); $filename = "original.pdf"; $tmpfile = tempnam($sharingFolder, date('YmdHis')); $svgFiles = ""; @@ -164,7 +167,7 @@ $f3->route('POST /share', return true; }, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, $sharingFolder, &$svgFiles) { if($formFieldName == "pdf") { - file_put_contents($sharingFolder."filename.txt", $fileBaseName); + file_put_contents($sharingFolder."/filename.txt", $fileBaseName); return $filename; } if($formFieldName == "svg") { @@ -229,12 +232,15 @@ $f3->route('GET /signature/@hash/pdf', $f3->route('POST /signature/@hash/save', function($f3) { $hash = Web::instance()->slug($f3->get('PARAMS.hash')); - $sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash.'/'; - $f3->set('UPLOADS', $sharingFolder); + $sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash; + $f3->set('UPLOADS', $sharingFolder.'/'); $tmpfile = tempnam($sharingFolder, date('YmdHis')); unlink($tmpfile); $svgFiles = ""; + $expireFile = $sharingFolder.".expire"; + touch($expireFile, date_format(date_modify(date_create(), file_get_contents($expireFile)), 'U')); + $files = Web::instance()->receive(function($file,$formFieldName){ if($formFieldName == "svg" && strpos(Web::instance()->mime($file['tmp_name'], true), 'image/svg+xml') !== 0) { $f3->error(403); @@ -275,6 +281,19 @@ $f3->route('GET /signature/@hash/nblayers', } ); +$f3->route('GET /cron', function($f3) { + $sharingFolder = $f3->get('PDF_STORAGE_PATH'); + foreach(glob($sharingFolder.'*.expire') as $expireFile) { + if(filemtime($expireFile) > time()) { + continue; + } + $expiredFolder = str_replace('.expire', '', $expireFile); + array_map('unlink', glob($expiredFolder."/*")); + rmdir($expiredFolder); + unlink($expireFile); + } +}); + $f3->route('GET /organization', function($f3) { $f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize'))))); diff --git a/public/js/signature.js b/public/js/signature.js index 54d37d2..71d4135 100644 --- a/public/js/signature.js +++ b/public/js/signature.js @@ -984,6 +984,12 @@ var modalSharing = function() { } } +var runCron = function() { + const xhr = new XMLHttpRequest(); + xhr.open('GET', '/cron'); + xhr.send(); +} + var pageUpload = async function() { document.querySelector('body').classList.remove('bg-light'); document.getElementById('input_pdf_upload').value = ''; @@ -1080,6 +1086,9 @@ var pageSignature = async function(url) { }; (function () { + if(sharingMode) { + setTimeout(function() { runCron() }, 2000); + } if(hash) { pageSignature('/signature/'+hash+'/pdf'); window.addEventListener('hashchange', function() { diff --git a/templates/signature.html.php b/templates/signature.html.php index 2be1aaa..e213ee1 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -175,6 +175,7 @@
En activant le partage de ce PDF vous allez pouvoir proposer un lien aux personnes de votre choix pour qu'elles puissent signer ce PDF.
Ce partage nécessite que le PDF soit transféré et stocké sur le serveur afin d'être accessible aux futurs signataires.
+Le PDF sera conservé après la dernière signature.
Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.
+Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.