From cb4ec9f1cf1381a2ceb426e060d0023ab711bec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Poujade?= <lois.poujade@tetras-libre.fr> Date: Mon, 2 May 2022 10:03:34 +0200 Subject: [PATCH] Remove base64, upload edited file to server Original file is duplicated, on creation, to 'original_<filename>.xyz'. Edit of this file we be saved as '<filename>.xyz' --- capsule-prototype/css/popup.css | 4 ++-- capsule-prototype/js/online-rekall/Tag.js | 3 +++ capsule-prototype/js/online-script.js | 15 ++++++--------- capsule-prototype/js/rekall/Document.js | 8 +++++--- capsule-prototype/php/upload.php | 14 ++++++++------ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/capsule-prototype/css/popup.css b/capsule-prototype/css/popup.css index 0e6eb0d..baea1c7 100644 --- a/capsule-prototype/css/popup.css +++ b/capsule-prototype/css/popup.css @@ -599,7 +599,7 @@ color: #FFF; } -#popupSetHighlight:hover { +#popupSetHighlight:hover, #editAnnotationPic:hover, #linkToOriginalImage:hover { color: rgba(255,255,255,.25); /*#142E33; */ } @@ -608,7 +608,7 @@ color: rgba(255,255,255,.75); /*#FFF; */ } -#popupEditSupprimer { +#popupEditSupprimer, #editAnnotationPic, #linkToOriginalImage { font-weight: 400; color: rgba(255,255,255,.75); font-size: 0.6em; diff --git a/capsule-prototype/js/online-rekall/Tag.js b/capsule-prototype/js/online-rekall/Tag.js index f45f159..f6cd7fe 100644 --- a/capsule-prototype/js/online-rekall/Tag.js +++ b/capsule-prototype/js/online-rekall/Tag.js @@ -101,6 +101,9 @@ Tag.prototype.downloadFile = function() { Tag.prototype.getDownloadLink = function(original = false) { return this.document.getDownloadLink(original); } +Tag.prototype.getFileName = function() { + return this.document.getFileName(); +} Tag.prototype.openBrowser = function() { return this.document.openBrowser(); } diff --git a/capsule-prototype/js/online-script.js b/capsule-prototype/js/online-script.js index 250e4cc..c28f555 100644 --- a/capsule-prototype/js/online-script.js +++ b/capsule-prototype/js/online-script.js @@ -558,9 +558,7 @@ function setEditionControls() { window.my_current_markerjs_data_in_ugly_global = state; markerArea.close(true); setMetaFromDom(keyDoc.value, "Rekall->MarkerjsState", btoa(JSON.stringify(state))); - setMetaFromDom(keyDoc.value, "Rekall->EditedImage", event.dataUrl); - /* this will create another annotation with edited image (as raw file, not b64 data) var b64img = event.dataUrl; var data = b64img.match(/data:([a-z]+)\/([a-z]+);base64,(.*)/); var type = data[1], subtype = data[2], b64data = data[3]; @@ -568,11 +566,9 @@ function setEditionControls() { var n = b64data.length; var uar = new Uint8Array(n); while (n--) uar[n] = bin_str.charCodeAt(n); - var file = new File([uar], 'edited_' + Math.floor(Math.random()*100) + '.' + subtype, {type: type+'/'+subtype}); + var file = new File([uar], keyDoc.value.substr(1), {type: type+'/'+subtype}); $('#left_menu_item_btn_addfile').files = [file]; - uploadFiles([file]); - */ - + uploadFiles([file], {'edited': 1}); }); markerArea.addEventListener('close', () => $('#edit_pic_modal').hide()); markerArea.renderAtNaturalSize = true; @@ -989,7 +985,7 @@ function fillPopupEdit(tag) { $("#popupImg").attr("src","../shared/css/images/img-note.png"); } else { if(tag.thumbnail.url){ - $("#popupImg").attr("src", tag.getMetadata('Rekall->EditedImage') || tag.thumbnail.url); + $("#popupImg").attr("src", tag.getDownloadLink() || tag.thumbnail.url); $('#annotation_img_edit').attr('src', tag.getDownloadLink(true)); } else { if(type.indexOf("image") > -1) $("#popupImg").attr("src","../shared/css/images/img-image.png") @@ -1021,7 +1017,7 @@ function fillPopupEdit(tag) { $('#editAnnotationPic').show(); $('#linkToOriginalImage').show(); $('#linkToOriginalImage').unbind('click'); - $('#linkToOriginalImage').click(() => tag.openBrowser()); + $('#linkToOriginalImage').click(() => window.open(tag.getDownloadLink(true), '_blank')); var data = tag.getMetadata('Rekall->MarkerjsState'); if (data) window.my_current_markerjs_data_in_ugly_global = JSON.parse(atob(data)); @@ -1217,7 +1213,7 @@ function deleteFromDomFinished() { //Gestion d'upload var filesToUpload = [], fileIsUploading = false; -function uploadFiles(files) { +function uploadFiles(files, additionnal_post_data={}) { $.each(files, function(index, file) { var formData = new FormData(); @@ -1254,6 +1250,7 @@ function uploadFiles(files) { formData.append("author", rekall_common.owner.author); formData.append("locationGps", rekall_common.owner.locationGps); formData.append("locationName", rekall_common.owner.locationName); + Object.keys(additionnal_post_data).forEach(k => formData.append(k, additionnal_post_data[k])); if(formData != undefined) { filesToUpload.push({ diff --git a/capsule-prototype/js/rekall/Document.js b/capsule-prototype/js/rekall/Document.js index 5627a3c..0582b29 100644 --- a/capsule-prototype/js/rekall/Document.js +++ b/capsule-prototype/js/rekall/Document.js @@ -88,9 +88,11 @@ Document.prototype.isLink = function(version) { } Document.prototype.getDownloadLink = function(original = false) { var path = Utils.getLocalFilePath(this, "file"); - if (original) - path = path.replace('file.php?r=', 'file.php?r=original_'); - return path; + return original ? path.replace('file.php?r=', 'file.php?r=original_') : path; +} +Document.prototype.getFileName = function() { + var path = Utils.getLocalFilePath(this, "file"); + return path.replace(/.*r=(.*)/, (f, m) => m); } diff --git a/capsule-prototype/php/upload.php b/capsule-prototype/php/upload.php index 36e882d..7f5cb52 100644 --- a/capsule-prototype/php/upload.php +++ b/capsule-prototype/php/upload.php @@ -58,14 +58,16 @@ if(is_uploaded_file($_FILES[$fileinfo]['tmp_name'])) { if(file_exists($_FILES[$fileinfo]['tmp_name'])) { if(is_writable($uploadFolder)) { - if(!file_exists($uploadFolder.$filename)) { + if(!file_exists($uploadFolder.$filename) || $_POST['edited'] == 1) { //echo "Upload de ".$fileinfo."\t".$filename."..."; if(move_uploaded_file($_FILES[$fileinfo]['tmp_name'], $uploadFolder.$filename)) { - copy($uploadFolder.$filename, $uploadFolder.'original_'.$filename); - $metasAdded = addFileToProject($uploadFolder.$filename, $metas, $tcIn, $tcOut); - $key = $metasAdded["key"]; - unset($metasAdded["key"]); - $retour .= '"code":1, "tcIn":'.$tcIn.', "tcOut":'.$tcOut.', "key":"'.$key.'", "status":"OK ('.(filesize($uploadFolder.$filename)/1000.).' kB)", "metas":'.json_encode($metasAdded); + if (!file_exists($uploadFolder.'original_'.$filename) && $_POST['edited'] != 1) { + copy($uploadFolder.$filename, $uploadFolder.'original_'.$filename); + $metasAdded = addFileToProject($uploadFolder.$filename, $metas, $tcIn, $tcOut); + $key = $metasAdded["key"]; + unset($metasAdded["key"]); + $retour .= '"code":1, "tcIn":'.$tcIn.', "tcOut":'.$tcOut.', "key":"'.$key.'", "status":"OK ('.(filesize($uploadFolder.$filename)/1000.).' kB)", "metas":'.json_encode($metasAdded); + } $status |= true; } else -- GitLab