mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
add function to upload files to seqta's storage
This commit is contained in:
+3
-3
@@ -284,7 +284,7 @@ async function finishLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chrome.storage.local.get(['justupdated'], function (result) {
|
chrome.storage.local.get(['justupdated'], function (result) {
|
||||||
if (result.justupdated) {
|
if (result.justupdated && !document.getElementById('whatsnewbk')) {
|
||||||
OpenWhatsNewPopup();
|
OpenWhatsNewPopup();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -530,10 +530,10 @@ async function LoadPageElements() {
|
|||||||
if (ranOnce) return;
|
if (ranOnce) return;
|
||||||
ranOnce = true;
|
ranOnce = true;
|
||||||
animate(
|
animate(
|
||||||
'.dashboard *:not(.dashlet-timetable), .dashboard .message *',
|
'.dashboard > *',
|
||||||
{ opacity: [0, 1], y: [10, 0] },
|
{ opacity: [0, 1], y: [10, 0] },
|
||||||
{
|
{
|
||||||
delay: stagger(0.01),
|
delay: stagger(0.1),
|
||||||
duration: 0.5,
|
duration: 0.5,
|
||||||
easing: [.22, .03, .26, 1]
|
easing: [.22, .03, .26, 1]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user