From 9c1ee08c2ee1b7a4b8a905c12b6e353ca214466b Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Mon, 27 Nov 2023 17:21:45 +1100 Subject: [PATCH] add function to upload files to seqta's storage --- src/SEQTA.js | 6 ++--- src/seqta/utils/FileUpload.js | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/seqta/utils/FileUpload.js diff --git a/src/SEQTA.js b/src/SEQTA.js index 774facc9..23662865 100644 --- a/src/SEQTA.js +++ b/src/SEQTA.js @@ -284,7 +284,7 @@ async function finishLoad() { } chrome.storage.local.get(['justupdated'], function (result) { - if (result.justupdated) { + if (result.justupdated && !document.getElementById('whatsnewbk')) { OpenWhatsNewPopup(); } }); @@ -530,10 +530,10 @@ async function LoadPageElements() { if (ranOnce) return; ranOnce = true; animate( - '.dashboard *:not(.dashlet-timetable), .dashboard .message *', + '.dashboard > *', { opacity: [0, 1], y: [10, 0] }, { - delay: stagger(0.01), + delay: stagger(0.1), duration: 0.5, easing: [.22, .03, .26, 1] } diff --git a/src/seqta/utils/FileUpload.js b/src/seqta/utils/FileUpload.js new file mode 100644 index 00000000..59536648 --- /dev/null +++ b/src/seqta/utils/FileUpload.js @@ -0,0 +1,43 @@ +/** + * Uploads an image file to a specified endpoint using a POST request. + * + * @param {File} file - The image file to be uploaded. + * @returns {Promise} A promise that resolves to the response from the server. + * @throws {Error} If no file is provided or if there is an error during upload. + */ +export async function UploadImage(file) { + // Ensuring that file is provided + if (!file) { + throw new Error("No file provided"); + } + + // Extracting the filename + const fileName = file.name; + + // Assuming 'document.cookie' contains all the cookies in the format you provided + const cookies = document.cookie; + + // Setting up the request options + const requestOptions = { + method: 'POST', + headers: { + 'Cookie': cookies, + 'X-File-Name': fileName + }, + body: file // Binary file data + }; + + // Making the fetch request and returning the promise + return fetch('/seqta/student/file/upload/xhr2', requestOptions) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + const json = response.json(); + return `/seqta/student/load/file?type=message&file=${json.uuid}`; + }) + .catch(error => { + console.error('Error during file upload:', error); + throw error; + }); +}