mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
PDF storage expiration time for multi-signature mode
This commit is contained in:
parent
b2ca7e81f3
commit
eca93fb359
29
app.php
29
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')))));
|
||||
|
@ -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() {
|
||||
|
@ -175,6 +175,7 @@
|
||||
<div class="modal-body">
|
||||
<p>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.</p>
|
||||
<p><i class="bi bi-hdd-network"></i> Ce partage nécessite que le PDF soit transféré et stocké sur le serveur afin d'être accessible aux futurs signataires.</p>
|
||||
<p class="mb-0"><i class="bi bi-hourglass-split"></i> Le PDF sera conservé <select name="duration" form="form_sharing"><option value="+1 year">un an</option><option value="+6 month">six mois</option><option value="+1 month" selected="selected">un mois</option><option value="+1 week">une semaine</option><option value="+1 day">un jour</option><option value="+1 hour">une heure</option></select> après la dernière signature.</p>
|
||||
</div>
|
||||
<div class="modal-footer text-center d-block">
|
||||
<form id="form_sharing" clas action="/share" method="post" enctype="multipart/form-data">
|
||||
@ -204,7 +205,7 @@
|
||||
<button onclick="navigator.clipboard.writeText(document.getElementById('input-share-link').value); this.innerText = 'Copié !';" autofocus="autofocus" class="btn btn-primary" type="button" id="btn-copy-share-link"><i class="bi bi-clipboard"></i> Copier</button>
|
||||
<script>document.querySelector('#input-share-link').value = document.location.href.replace(/#.*/, '');</script>
|
||||
</div>
|
||||
<p>Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.</p>
|
||||
<p class="mb-0">Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.</p>
|
||||
</div>
|
||||
<div class="modal-footer text-start">
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Fermer</button>
|
||||
@ -242,11 +243,12 @@
|
||||
<script>
|
||||
var maxSize = <?php echo $maxSize ?>;
|
||||
var maxPage = <?php echo $maxPage ?>;
|
||||
var sharingMode = <?php echo intval(!isset($noSharingMode)) ?>;
|
||||
var hash = null;
|
||||
<?php if(isset($hash)): ?>
|
||||
hash = "<?php echo $hash ?>";
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
<script src="/js/signature.js?202204150047"></script>
|
||||
<script src="/js/signature.js?202204270035"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user