mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
Merge branch 'sharing' of github.com:24eme/signaturepdf into sharing
This commit is contained in:
commit
0ca295070d
39
app.php
39
app.php
@ -53,6 +53,18 @@ $f3->route('GET /signature',
|
|||||||
echo View::instance()->render('signature.html.php');
|
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',
|
$f3->route('GET /organization',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
|
$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',
|
$f3->route('POST /organize',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$filename = null;
|
$filename = null;
|
||||||
|
@ -28,6 +28,7 @@ var loadPDF = async function(pdfBlob, filename) {
|
|||||||
type: 'application/pdf'
|
type: 'application/pdf'
|
||||||
}));
|
}));
|
||||||
document.getElementById('input_pdf').files = dataTransfer.files;
|
document.getElementById('input_pdf').files = dataTransfer.files;
|
||||||
|
document.getElementById('input_pdf_share').files = dataTransfer.files;
|
||||||
|
|
||||||
var loadingTask = pdfjsLib.getDocument(url);
|
var loadingTask = pdfjsLib.getDocument(url);
|
||||||
loadingTask.promise.then(function(pdf) {
|
loadingTask.promise.then(function(pdf) {
|
||||||
@ -946,7 +947,15 @@ var pageSignature = async function(url) {
|
|||||||
fontCaveat = font;
|
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) {
|
if(!pdfBlob) {
|
||||||
document.location = '/signature';
|
document.location = '/signature';
|
||||||
return;
|
return;
|
||||||
@ -961,6 +970,11 @@ var pageSignature = async function(url) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
if(hash) {
|
||||||
|
pageSignature('/signature/'+hash+'/pdf');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(window.location.hash && window.location.hash.match(/^\#http/)) {
|
if(window.location.hash && window.location.hash.match(/^\#http/)) {
|
||||||
let hashUrl = window.location.hash.replace(/^\#/, '');
|
let hashUrl = window.location.hash.replace(/^\#/, '');
|
||||||
pageUpload();
|
pageUpload();
|
||||||
|
@ -70,14 +70,21 @@
|
|||||||
<div class="d-grid gap-2 mt-2">
|
<div class="d-grid gap-2 mt-2">
|
||||||
<button type="button" id="btn-add-svg" class="btn btn-sm btn-light" data-bs-toggle="modal" data-bs-target="#modalAddSvg"><i class="bi bi-plus-circle"></i> Ajouter un élément</button>
|
<button type="button" id="btn-add-svg" class="btn btn-sm btn-light" data-bs-toggle="modal" data-bs-target="#modalAddSvg"><i class="bi bi-plus-circle"></i> Ajouter un élément</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="position-absolute bottom-0 pb-2 ps-0 pe-4 w-100 d-none d-sm-none d-md-block">
|
||||||
<form class="position-absolute bottom-0 pb-2 ps-0 pe-4 w-100 d-none d-sm-none d-md-block" id="form_pdf" action="/sign" method="post" enctype="multipart/form-data">
|
<form id="form_sharing" action="/share" method="post" enctype="multipart/form-data">
|
||||||
<input id="input_pdf" name="pdf" type="file" class="d-none" />
|
<input id="input_pdf_share" name="pdf" type="file" class="d-none" />
|
||||||
<input id="input_svg" name="svg[]" type="file" class="d-none" />
|
<div class="d-grid gap-2 mt-2">
|
||||||
<div class="d-grid gap-2 mt-2">
|
<button class="btn btn-outline-secondary" type="submit" id="save"><i class="bi bi-share"></i> Partager ce PDF</button>
|
||||||
<button class="btn btn-primary" disabled="disabled" type="submit" id="save"><i class="bi bi-download"></i> Télécharger le PDF Signé</button>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
<form id="form_pdf" action="/sign" method="post" enctype="multipart/form-data">
|
||||||
|
<input id="input_pdf" name="pdf" type="file" class="d-none" />
|
||||||
|
<input id="input_svg" name="svg[]" type="file" class="d-none" />
|
||||||
|
<div class="d-grid gap-2 mt-2">
|
||||||
|
<button class="btn btn-primary" disabled="disabled" type="submit" id="save"><i class="bi bi-download"></i> Télécharger le PDF Signé</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="position-fixed top-0 start-0 bg-white w-100 p-2 shadow-sm d-md-none">
|
<div class="position-fixed top-0 start-0 bg-white w-100 p-2 shadow-sm d-md-none">
|
||||||
@ -150,6 +157,10 @@
|
|||||||
<script>
|
<script>
|
||||||
var maxSize = <?php echo $maxSize ?>;
|
var maxSize = <?php echo $maxSize ?>;
|
||||||
var maxPage = <?php echo $maxPage ?>;
|
var maxPage = <?php echo $maxPage ?>;
|
||||||
|
var hash = null;
|
||||||
|
<?php if(isset($hash)): ?>
|
||||||
|
hash = "<?php echo $hash ?>";
|
||||||
|
<?php endif; ?>
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/signature.js?202203261059"></script>
|
<script src="/js/signature.js?202203261059"></script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user