Fix sending mail in guest mode

This commit is contained in:
Booteille 2024-12-07 15:09:32 +01:00
parent 3640e22239
commit cc3cc0681a
No known key found for this signature in database
GPG Key ID: 0FE17AFD5A1F837F
2 changed files with 36 additions and 43 deletions

View File

@ -100,29 +100,27 @@ document.addEventListener("DOMContentLoaded", () => {
/** /**
* [Invitation feature] Send URLs of files to server * [Invitation feature] Send URLs of files to server
*/ */
const sendFilesURLs = () => { const sendGuestFiles = (fileURL) => {
if (filesURLs.length > 0) { fetch(sendGuestFileURL, {
fetch(sendFilesURLsURL, { method: "POST",
method: "POST", headers: {
headers: { "Content-Type": "application/json",
"Content-Type": "application/json", },
}, body: JSON.stringify({
body: JSON.stringify({ urls: [fileURL],
urls: filesURLs, }),
}), })
.then((response) => response.json())
.then((data) => {
if (data.success) {
notify(data.msg, "success");
} else {
notify(data.msg, "danger");
}
}) })
.then((response) => response.json()) .catch((error) => {
.then((data) => { console.error("Error:", error);
if (data.success) { });
notify(data.msg, "success");
} else {
notify(data.msg, "danger");
}
})
.catch((error) => {
console.error("Error:", error);
});
}
}; };
/** /**
@ -203,8 +201,8 @@ document.addEventListener("DOMContentLoaded", () => {
job.lufiFile.delay === 0 job.lufiFile.delay === 0
? i18n.noLimit ? i18n.noLimit
: `${i18n.expiration} ${formatDate( : `${i18n.expiration} ${formatDate(
job.lufiFile.delay * 86400 + job.lufiFile.createdAt job.lufiFile.delay * 86400 + job.lufiFile.createdAt
)}`; )}`;
if (job.lufiFile.type === "application/zip") { if (job.lufiFile.type === "application/zip") {
uploadedFileCard uploadedFileCard
@ -224,11 +222,10 @@ document.addEventListener("DOMContentLoaded", () => {
job.lufiFile.downloadUrl(); job.lufiFile.downloadUrl();
uploadedFileCard.querySelector(".action-delete").href = uploadedFileCard.querySelector(".action-delete").href =
job.lufiFile.removeUrl(); job.lufiFile.removeUrl();
uploadedFileCard.querySelector(".action-share").href = `${ uploadedFileCard.querySelector(".action-share").href = `${job.lufiFile.serverUrl
job.lufiFile.serverUrl }m?links=${encodeURIComponent(
}m?links=${encodeURIComponent( '["' + job.lufiFile.keys.server + '"]'
'["' + job.lufiFile.keys.server + '"]' )}`;
)}`;
uploadedFileCard uploadedFileCard
.querySelector(".action-copy") .querySelector(".action-copy")
@ -266,19 +263,15 @@ document.addEventListener("DOMContentLoaded", () => {
} }
if (isGuest && job.lufiFile.keys.server !== null) { if (isGuest && job.lufiFile.keys.server !== null) {
filesURLs.push( sendGuestFiles(JSON.stringify({
JSON.stringify({ name: job.lufiFile.name,
name: job.lufiFile.name, short: job.lufiFile.keys.server,
short: job.lufiFile.keys.server, url: job.lufiFile.downloadUrl(),
url: job.lufiFile.downloadUrl(), size: job.lufiFile.size,
size: job.lufiFile.size, created_at: job.lufiFile.createdAt,
created_at: job.lufiFile.createdAt, delay,
delay, token: job.lufiFile.actionToken,
token: job.lufiFile.actionToken, }));
})
);
sendFilesURLs();
} }
return okAsync(job); return okAsync(job);

View File

@ -342,7 +342,7 @@ const maxSize = <%= config('max_file_size') || 0 %>;
% if (defined stash('invitation')) { % if (defined stash('invitation')) {
const isGuest = true; 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 { % } else {
const isGuest = false; const isGuest = false;
% } % }