mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
Conservation du nom original du fichier du pdf dans le localstorage de
l'utilisateur pour pouvoir le restituer lors du téléchargement du pdf signé sans qu'il soit stocké sur le serveur
This commit is contained in:
parent
7375eb298c
commit
44e38ae4e5
19
app.php
19
app.php
@ -21,6 +21,7 @@ $f3->route('GET /',
|
|||||||
);
|
);
|
||||||
$f3->route('POST /upload',
|
$f3->route('POST /upload',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
|
$fileName = null;
|
||||||
$files = Web::instance()->receive(function($file,$formFieldName){
|
$files = Web::instance()->receive(function($file,$formFieldName){
|
||||||
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
|
if(Web::instance()->mime($file['tmp_name'], true) != 'application/pdf') {
|
||||||
|
|
||||||
@ -31,8 +32,8 @@ $f3->route('POST /upload',
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, true, function($fileBaseName, $formFieldName) {
|
}, true, function($fileBaseName, $formFieldName) use (&$fileName) {
|
||||||
|
$fileName = $fileBaseName;
|
||||||
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).".pdf";
|
return substr(hash('sha256', $fileBaseName.uniqid().mt_rand()), 0, 24).".pdf";
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,12 +49,20 @@ $f3->route('POST /upload',
|
|||||||
$f3->error(403);
|
$f3->error(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($fileName) {
|
||||||
|
$f3->set('SESSION.fileName', $fileName);
|
||||||
|
}
|
||||||
|
|
||||||
return $f3->reroute('/'.$key);
|
return $f3->reroute('/'.$key);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$f3->route('GET /@key',
|
$f3->route('GET /@key',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$f3->set('key', $f3->get('PARAMS.key'));
|
$f3->set('key', $f3->get('PARAMS.key'));
|
||||||
|
if($f3->get('SESSION.fileName')) {
|
||||||
|
$f3->set('fileName', $f3->get('SESSION.fileName'));
|
||||||
|
$f3->clear('SESSION.fileName');
|
||||||
|
}
|
||||||
echo View::instance()->render('pdf.html.php');
|
echo View::instance()->render('pdf.html.php');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -110,6 +119,10 @@ $f3->route('POST /@key/save',
|
|||||||
function($f3) {
|
function($f3) {
|
||||||
$key = $f3->get('PARAMS.key');
|
$key = $f3->get('PARAMS.key');
|
||||||
$svgData = $_POST['svg'];
|
$svgData = $_POST['svg'];
|
||||||
|
$filename = null;
|
||||||
|
if(isset($_POST['filename']) && $_POST['filename']) {
|
||||||
|
$filename = str_replace(".pdf", "_signe.pdf", $_POST['filename']);
|
||||||
|
}
|
||||||
|
|
||||||
$svgFiles = "";
|
$svgFiles = "";
|
||||||
foreach($svgData as $index => $svgItem) {
|
foreach($svgData as $index => $svgItem) {
|
||||||
@ -121,7 +134,7 @@ $f3->route('POST /@key/save',
|
|||||||
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $f3->get('UPLOADS').$key.'.svg.pdf', $svgFiles));
|
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $f3->get('UPLOADS').$key.'.svg.pdf', $svgFiles));
|
||||||
shell_exec(sprintf("pdftk %s multibackground %s output %s", $f3->get('UPLOADS').$key.'.svg.pdf', $f3->get('UPLOADS').$key.'.pdf', $f3->get('UPLOADS').$key.'_signe.pdf'));
|
shell_exec(sprintf("pdftk %s multibackground %s output %s", $f3->get('UPLOADS').$key.'.svg.pdf', $f3->get('UPLOADS').$key.'.pdf', $f3->get('UPLOADS').$key.'_signe.pdf'));
|
||||||
|
|
||||||
Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf');
|
Web::instance()->send($f3->get('UPLOADS').$key.'_signe.pdf', null, 0, TRUE, $filename);
|
||||||
|
|
||||||
if($f3->get('DEBUG')) {
|
if($f3->get('DEBUG')) {
|
||||||
return;
|
return;
|
||||||
|
@ -20,11 +20,16 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
var pdfPages = [];
|
var pdfPages = [];
|
||||||
var svgCollections = [];
|
var svgCollections = [];
|
||||||
var resizeTimeout;
|
var resizeTimeout;
|
||||||
|
var pdfHistory = {};
|
||||||
var currentScale = 1.5;
|
var currentScale = 1.5;
|
||||||
var windowWidth = window.innerWidth;
|
var windowWidth = window.innerWidth;
|
||||||
var menu = document.getElementById('offcanvasTop')
|
var menu = document.getElementById('offcanvasTop')
|
||||||
var menuOffcanvas = new bootstrap.Offcanvas(menu)
|
var menuOffcanvas = new bootstrap.Offcanvas(menu)
|
||||||
|
|
||||||
|
if(localStorage.getItem('pdfHistory')) {
|
||||||
|
pdfHistory = JSON.parse(localStorage.getItem('pdfHistory'));
|
||||||
|
}
|
||||||
|
|
||||||
var is_mobile = function() {
|
var is_mobile = function() {
|
||||||
return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none");
|
return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none");
|
||||||
}
|
}
|
||||||
@ -438,6 +443,10 @@ loadingTask.promise.then(function(pdf) {
|
|||||||
xhr.send( formData );
|
xhr.send( formData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(filename) {
|
||||||
|
document.getElementById('input_filename').value = filename;
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('save').addEventListener('click', function(event) {
|
document.getElementById('save').addEventListener('click', function(event) {
|
||||||
canvasEditions.forEach(function(canvasEdition, index) {
|
canvasEditions.forEach(function(canvasEdition, index) {
|
||||||
document.getElementById('data-svg-'+index).value = canvasEdition.toSVG();
|
document.getElementById('data-svg-'+index).value = canvasEdition.toSVG();
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<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="/<?php echo $key ?>/save" method="post">
|
<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="/<?php echo $key ?>/save" method="post">
|
||||||
|
<input id="input_filename" type="hidden" name="filename" value="" />
|
||||||
<div class="d-grid gap-2 mt-2">
|
<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>
|
<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>
|
||||||
@ -144,6 +145,21 @@
|
|||||||
<script src="/vendor/opentype.min.js?1.3.3"></script>
|
<script src="/vendor/opentype.min.js?1.3.3"></script>
|
||||||
<script>
|
<script>
|
||||||
var url = '/<?php echo $key ?>/pdf';
|
var url = '/<?php echo $key ?>/pdf';
|
||||||
|
var pdfHistory = {};
|
||||||
|
var filename = null;
|
||||||
|
if(localStorage.getItem('pdfHistory')) {
|
||||||
|
pdfHistory = JSON.parse(localStorage.getItem('pdfHistory'));
|
||||||
|
}
|
||||||
|
<?php if(isset($fileName)): ?>
|
||||||
|
pdfHistoryItem = {};
|
||||||
|
pdfHistoryItem.filename = "<?php echo $fileName ?>";
|
||||||
|
pdfHistoryItem.key = "<?php echo $key ?>";
|
||||||
|
pdfHistory[pdfHistoryItem.key] = pdfHistoryItem;
|
||||||
|
localStorage.setItem('pdfHistory', JSON.stringify(pdfHistory));
|
||||||
|
<?php endif;?>
|
||||||
|
if(pdfHistory["<?php echo $key ?>"]) {
|
||||||
|
filename = pdfHistory["<?php echo $key ?>"].filename;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/app.js"></script>
|
<script src="/js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -130,13 +130,13 @@ describe("Signature d'un pdf", () => {
|
|||||||
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './tests/downloads'});
|
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './tests/downloads'});
|
||||||
await page.click("#save");
|
await page.click("#save");
|
||||||
await page.waitForTimeout(500);
|
await page.waitForTimeout(500);
|
||||||
await expect(require('fs').existsSync('./tests/downloads/'+hash+'_signe.pdf')).toBe(true);
|
await expect(require('fs').existsSync('./tests/downloads/document_signe.pdf')).toBe(true);
|
||||||
});
|
});
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
if(process.env.DEBUG) {
|
if(process.env.DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await require('fs').unlinkSync('./tests/downloads/'+hash+'_signe.pdf');
|
await require('fs').unlinkSync('./tests/downloads/document_signe.pdf');
|
||||||
await server.kill();
|
await server.kill();
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user