From 333a3823a4aa91a6f147ad6b0fa381c28b3fbb27 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Fri, 29 Aug 2025 15:37:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E2=80=94=20Fix=20bug=20in=20POS?= =?UTF-8?q?T=20file=20deletion=20(#319)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 3 +++ lib/Lufi/Controller/Files.pm | 9 +++++---- themes/default/public/js/lufi-common.js | 15 +++++++++++++++ themes/default/public/js/lufi-files.js | 18 +----------------- themes/default/templates/msg.html.ep | 7 +++++++ 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7300ba7..2dce818 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ Revision history for Lufi 0.08.0 ????-??-?? +0.07.2 ????-??-?? + - 🐛 — Fix bug in POST file deletion (#319) + 0.07.1 2025-07-16 - 🚚 — Use POST to delete a file instead of GET diff --git a/lib/Lufi/Controller/Files.pm b/lib/Lufi/Controller/Files.pm index d83dadf..889d57f 100644 --- a/lib/Lufi/Controller/Files.pm +++ b/lib/Lufi/Controller/Files.pm @@ -470,7 +470,7 @@ sub delete { my $token = $c->param('token'); if ((!defined($c->config('ldap')) && !defined($c->config('htpasswd')) && !defined($c->config('auth_headers'))) || $c->is_user_authenticated) { - if ($c->validation->csrf_protect->has_error('csrf_token')) { + if (!(defined($c->param('_format')) && $c->param('_format') eq 'json') && $c->validation->csrf_protect->has_error('csrf_token')) { $c->flash(msg => $c->l('Bad CSRF token.')); $c->redirect_to('delete', $short, $token); } else { @@ -495,9 +495,10 @@ sub delete { }, any => sub { $c->render( - template => 'msg', - f => $ldfile, - msg => $msg + template => 'msg', + f => $ldfile, + msg => $msg, + del_short_from_localstorage => $short ); } ); diff --git a/themes/default/public/js/lufi-common.js b/themes/default/public/js/lufi-common.js index 75db513..a33369a 100644 --- a/themes/default/public/js/lufi-common.js +++ b/themes/default/public/js/lufi-common.js @@ -27,6 +27,21 @@ function formatDate(unixTimestamp) { minute: '2-digit', }) } +function delItem(name) { + var files = localStorage.getItem(`${window.prefix}files`); + if (files === null) { + files = new Array(); + } else { + files = JSON.parse(files); + } + var i; + for (i = 0; i < files.length; i++) { + if (files[i].short === name) { + files.splice(i, 1); + } + } + localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); +} $(document).ready(function(){ $('select').material_select(); $(".select-lang select").on('change', changeLang); diff --git a/themes/default/public/js/lufi-files.js b/themes/default/public/js/lufi-files.js index 325469a..e645d49 100644 --- a/themes/default/public/js/lufi-files.js +++ b/themes/default/public/js/lufi-files.js @@ -11,22 +11,6 @@ function addItem(item) { localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); } -function delItem(name) { - var files = localStorage.getItem(`${window.prefix}files`); - if (files === null) { - files = new Array(); - } else { - files = JSON.parse(files); - } - var i; - for (i = 0; i < files.length; i++) { - if (files[i].short === name) { - files.splice(i, 1); - } - } - localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); -} - function itemExists(name) { var files = localStorage.getItem(`${window.prefix}files`); if (files === null) { @@ -140,7 +124,7 @@ function delFile() { var short = $(this).attr('data-short'); $.ajax({ url: dlink, - method: 'GET', + method: 'POST', data: { _format: 'json' }, diff --git a/themes/default/templates/msg.html.ep b/themes/default/templates/msg.html.ep index e7a3b0f..4b7f6f8 100644 --- a/themes/default/templates/msg.html.ep +++ b/themes/default/templates/msg.html.ep @@ -20,3 +20,10 @@ +% if (defined stash('del_short_from_localstorage')) { + +% }