1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

Storing and display filename in sharing mode

This commit is contained in:
Vincent LAURENT 2022-04-01 00:52:44 +02:00
parent 0cc5ba6439
commit 1e925a38a0
2 changed files with 15 additions and 5 deletions

11
app.php
View File

@ -183,8 +183,9 @@ $f3->route('POST /share',
}
return true;
}, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, &$svgFiles) {
}, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, $sharingFolder, &$svgFiles) {
if($formFieldName == "pdf") {
file_put_contents($sharingFolder."filename.txt", $fileBaseName);
return $filename;
}
if($formFieldName == "svg") {
@ -252,6 +253,10 @@ $f3->route('GET /signature/@hash/pdf',
$files = scandir($sharingFolder);
$originalFile = $sharingFolder.'/original.pdf';
$finalFile = $sharingFolder.'/'.$f3->get('PARAMS.hash').'.pdf';
$filename = $f3->get('PARAMS.hash').'.pdf';
if(file_exists($sharingFolder."/filename.txt")) {
$filename = file_get_contents($sharingFolder."/filename.txt");
}
$layers = [];
foreach($files as $file) {
if(strpos($file, 'svg.pdf') !== false) {
@ -259,14 +264,14 @@ $f3->route('GET /signature/@hash/pdf',
}
}
if (!$layers) {
Web::instance()->send($originalFile, null, 0, TRUE, $f3->get('PARAMS.hash').'.pdf');
Web::instance()->send($originalFile, null, 0, TRUE, $filename);
}
$bufferFile = str_replace('.pdf', '_tmp.pdf', $originalFile);
shell_exec(sprintf("cp %s %s", $originalFile, $finalFile));
foreach($layers as $layer) {
shell_exec(sprintf("pdftk %1\$s multistamp %2\$s output %3\$s && mv %3\$s %1\$s", $finalFile, $layer, $bufferFile));
}
Web::instance()->send($finalFile, null, 0, TRUE, $f3->get('PARAMS.hash').'.pdf');
Web::instance()->send($finalFile, null, 0, TRUE, $filename);
}
);

View File

@ -968,8 +968,6 @@ var pageSignature = async function(url) {
modalSigned.show();
}
let filename = url.replace('/pdf/', '');
document.title = filename + ' - ' + document.title;
document.getElementById('page-upload').classList.add('d-none');
document.getElementById('page-signature').classList.remove('d-none');
fabric.Textbox.prototype._wordJoiners = /[]/;
@ -987,6 +985,7 @@ var pageSignature = async function(url) {
});
let pdfBlob = null;
let filename = url.replace('/pdf/', '');
if(hash) {
var response = await fetch(url);
@ -994,9 +993,15 @@ var pageSignature = async function(url) {
return;
}
pdfBlob = await response.blob();
if(response.headers.get('Content-Disposition').match(/attachment; filename="/)) {
filename = response.headers.get('Content-Disposition').replace(/^[^"]*"/, "").replace(/"[^"]*$/, "");
}
} else {
pdfBlob = await getPDFBlobFromCache(url);
}
document.title = filename + ' - ' + document.title;
if(!pdfBlob) {
document.location = '/signature';
return;