From cc3cc0681a4cced8bc7a5abfcdad2f54860680b5 Mon Sep 17 00:00:00 2001 From: Booteille Date: Sat, 7 Dec 2024 15:09:32 +0100 Subject: [PATCH] Fix sending mail in guest mode --- themes/default/public/js/upload.js | 77 ++++++++++++-------------- themes/default/templates/index.html.ep | 2 +- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/themes/default/public/js/upload.js b/themes/default/public/js/upload.js index 1625c52..bcf0e84 100644 --- a/themes/default/public/js/upload.js +++ b/themes/default/public/js/upload.js @@ -100,29 +100,27 @@ document.addEventListener("DOMContentLoaded", () => { /** * [Invitation feature] Send URLs of files to server */ - const sendFilesURLs = () => { - if (filesURLs.length > 0) { - fetch(sendFilesURLsURL, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - urls: filesURLs, - }), + const sendGuestFiles = (fileURL) => { + fetch(sendGuestFileURL, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + urls: [fileURL], + }), + }) + .then((response) => response.json()) + .then((data) => { + if (data.success) { + notify(data.msg, "success"); + } else { + notify(data.msg, "danger"); + } }) - .then((response) => response.json()) - .then((data) => { - if (data.success) { - notify(data.msg, "success"); - } else { - notify(data.msg, "danger"); - } - }) - .catch((error) => { - console.error("Error:", error); - }); - } + .catch((error) => { + console.error("Error:", error); + }); }; /** @@ -203,8 +201,8 @@ document.addEventListener("DOMContentLoaded", () => { job.lufiFile.delay === 0 ? i18n.noLimit : `${i18n.expiration} ${formatDate( - job.lufiFile.delay * 86400 + job.lufiFile.createdAt - )}`; + job.lufiFile.delay * 86400 + job.lufiFile.createdAt + )}`; if (job.lufiFile.type === "application/zip") { uploadedFileCard @@ -224,11 +222,10 @@ document.addEventListener("DOMContentLoaded", () => { job.lufiFile.downloadUrl(); uploadedFileCard.querySelector(".action-delete").href = job.lufiFile.removeUrl(); - uploadedFileCard.querySelector(".action-share").href = `${ - job.lufiFile.serverUrl - }m?links=${encodeURIComponent( - '["' + job.lufiFile.keys.server + '"]' - )}`; + uploadedFileCard.querySelector(".action-share").href = `${job.lufiFile.serverUrl + }m?links=${encodeURIComponent( + '["' + job.lufiFile.keys.server + '"]' + )}`; uploadedFileCard .querySelector(".action-copy") @@ -266,19 +263,15 @@ document.addEventListener("DOMContentLoaded", () => { } if (isGuest && job.lufiFile.keys.server !== null) { - filesURLs.push( - JSON.stringify({ - name: job.lufiFile.name, - short: job.lufiFile.keys.server, - url: job.lufiFile.downloadUrl(), - size: job.lufiFile.size, - created_at: job.lufiFile.createdAt, - delay, - token: job.lufiFile.actionToken, - }) - ); - - sendFilesURLs(); + sendGuestFiles(JSON.stringify({ + name: job.lufiFile.name, + short: job.lufiFile.keys.server, + url: job.lufiFile.downloadUrl(), + size: job.lufiFile.size, + created_at: job.lufiFile.createdAt, + delay, + token: job.lufiFile.actionToken, + })); } return okAsync(job); diff --git a/themes/default/templates/index.html.ep b/themes/default/templates/index.html.ep index c356193..ef3d47e 100644 --- a/themes/default/templates/index.html.ep +++ b/themes/default/templates/index.html.ep @@ -342,7 +342,7 @@ const maxSize = <%= config('max_file_size') || 0 %>; % if (defined stash('invitation')) { const isGuest = true; -const sendFilesURLsURL = '<%= url_for('guest_send_mail', token => stash('invitation')->token)->to_abs() %>'; +const sendGuestFileURL = '<%= url_for('guest_send_mail', token => stash('invitation')->token)->to_abs() %>'; % } else { const isGuest = false; % }