diff --git a/app.php b/app.php index 56597c4..30cb407 100644 --- a/app.php +++ b/app.php @@ -8,11 +8,8 @@ if(getenv("DEBUG")) { $f3->set('ROOT', __DIR__); $f3->set('UI', $f3->get('ROOT')."/templates/"); -$f3->set('UPLOADS', $f3->get('ROOT').'/data/'); +$f3->set('UPLOADS', sys_get_temp_dir()."/"); -if(!is_dir($f3->get('UPLOADS'))) { - mkdir($f3->get('UPLOADS')); -} $f3->route('GET /', function($f3) { $f3->set('key', hash('md5', uniqid().rand())); @@ -51,6 +48,12 @@ $f3->route('POST /upload', $f3->error(403); } + if($f3->get('DEBUG')) { + return; + } + + unlink($filePdf); + return $f3->reroute('/'.$key); } ); @@ -103,12 +106,37 @@ $f3->route('POST /image2svg', if($f3->get('DEBUG')) { return; } + array_map('unlink', glob($imageFile."*")); } ); $f3->route('POST /@key/save', function($f3) { $key = $f3->get('PARAMS.key'); + $files = Web::instance()->receive(function($file,$formFieldName){ + if(strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) { + + return false; + } + + return true; + }, true, function($fileBaseName, $formFieldName) use ($key) { + + return $key.".pdf"; + }); + + $pdfFile = null; + foreach($files as $file => $valid) { + if(!$valid) { + continue; + } + $pdfFile = $file; + } + + if(!$pdfFile) { + $f3->error(403); + } + $svgData = $_POST['svg']; $filename = null; if(isset($_POST['filename']) && $_POST['filename']) { @@ -130,9 +158,7 @@ $f3->route('POST /@key/save', if($f3->get('DEBUG')) { return; } - array_map('unlink', glob($f3->get('UPLOADS').$key."_*.svg")); - unlink($f3->get('UPLOADS').$key.'.svg.pdf'); - unlink($f3->get('UPLOADS').$key.'_signe.pdf'); + array_map('unlink', glob($f3->get('UPLOADS').$key."*")); } ); diff --git a/public/js/app.js b/public/js/app.js index 109d3c2..737fb45 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,3 +1,16 @@ +var canvasEditions = []; +(async function () { + +const cache = await caches.open('pdf'); +var responsePdf = await cache.match(url); +var pdfBlob = await responsePdf.blob(); +url = await URL.createObjectURL(pdfBlob); + +var dataTransfer = new DataTransfer(); +dataTransfer.items.add(new File([pdfBlob], filename, { + type: 'application/pdf' +})); +document.getElementById('input_pdf').files = dataTransfer.files; // Loaded via diff --git a/templates/pdf.html.php b/templates/pdf.html.php index cd7b24a..0fd92ac 100644 --- a/templates/pdf.html.php +++ b/templates/pdf.html.php @@ -68,8 +68,9 @@ -
+ +