show upload to user

This commit is contained in:
Mylloon 2022-10-10 20:51:01 +02:00
parent e15890b3e6
commit c124d3cf04
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -11,7 +11,7 @@ const main = () => {
const input = document.getElementById("upload"); const input = document.getElementById("upload");
input.onchange = () => { input.onchange = () => {
fetchFile(input.files); fetchFile(input.files, input);
}; };
}; };
@ -19,9 +19,9 @@ const main = () => {
* Check if they're is only one file and send it * Check if they're is only one file and send it
* @param list List of files * @param list List of files
*/ */
const fetchFile = (list) => { const fetchFile = (list, element = undefined) => {
if (list.length == 1) { if (list.length == 1) {
send(list[0]); send(list[0], element);
} }
}; };
@ -29,7 +29,16 @@ const fetchFile = (list) => {
* Send a file to the server * Send a file to the server
* @param file File to send * @param file File to send
*/ */
const send = (file) => { const send = (file, element) => {
// Show the user a file is uploading
if (element) {
let parent = element.parentElement;
parent.textContent = "";
let newText = document.createElement("h3");
newText.textContent = "Téléversement...";
parent.appendChild(newText);
}
// TODO: Encrypt the file before sending it // TODO: Encrypt the file before sending it
const data = new FormData(); const data = new FormData();
data.append("file", file); data.append("file", file);