From 82b1dcc9130f2777309e916a55032f65194191af Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Fri, 12 Nov 2021 01:49:23 +0100 Subject: [PATCH] =?UTF-8?q?Le=20pdf=20est=20stock=C3=A9=20en=20local=20dan?= =?UTF-8?q?s=20le=20CacheAPI=20et=20il=20transite=20mais=20n'est=20plus=20?= =?UTF-8?q?conserv=C3=A9=20sur=20le=20serveur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.php | 40 ++++++++++++++++---- public/js/app.js | 16 +++++++- templates/index.html.php | 80 ++++++++++++++++++++++++---------------- templates/pdf.html.php | 3 +- 4 files changed, 97 insertions(+), 42 deletions(-) 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 @@ -
+ +