fixes and functions

This commit is contained in:
Mateusz Gruszczyński
2026-08-04 23:21:27 +02:00
parent 6fc408ddf7
commit 4b25085bb5
28 changed files with 306 additions and 330 deletions
+9 -5
View File
@@ -70,7 +70,7 @@ function safeAttachmentUrl(value) {
: safePublicUrl(raw, { allowMailto: false });
}
export function bindNoteFiles({ editor, endpoints, getAccessToken, canDelete, canUpload, canEdit = () => true, toast, onFilesChanged = () => { } }) {
export function bindNoteFiles({ editor, endpoints, getAccessToken, getUploadMaxSize = () => 0, canDelete, canUpload, canEdit = () => true, toast, onFilesChanged = () => { } }) {
const dialog = document.querySelector("#files-dialog");
const list = document.querySelector("#files-list");
const input = document.querySelector("#file-input");
@@ -126,6 +126,7 @@ export function bindNoteFiles({ editor, endpoints, getAccessToken, canDelete, ca
method: "POST",
body: form,
headers: {},
uploadMaxSizeBytes: getUploadMaxSize(),
onProgress: progress => uploadToast.update(progress),
});
if (completed) return;
@@ -143,13 +144,16 @@ export function bindNoteFiles({ editor, endpoints, getAccessToken, canDelete, ca
await run();
}
document.querySelector("#upload-button").addEventListener("click", () => {
function requestUpload() {
if (!canUpload() || !canEdit()) {
toast("Log in with read-write access to upload files.");
toast("You need read-write access and upload permission to upload files.");
return;
}
input.click();
});
}
document.querySelector("#upload-button")?.addEventListener("click", requestUpload);
document.querySelector("#mobile-upload-button")?.addEventListener("click", requestUpload);
input.addEventListener("change", async event => {
let file = event.target.files[0];
@@ -175,7 +179,7 @@ export function bindNoteFiles({ editor, endpoints, getAccessToken, canDelete, ca
if (!files.length) return;
event.preventDefault();
if (!canUpload() || !canEdit()) {
toast("Log in with read-write access to paste files.");
toast("You need read-write access and upload permission to paste files.");
return;
}