Create script.js

This commit is contained in:
Voxel 2025-04-13 20:06:45 -04:00 committed by GitHub
parent 3798bcd836
commit 60090f6f01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

53
host/script.js Normal file
View file

@ -0,0 +1,53 @@
async function uploadFile() {
const fileInput = document.getElementById("file");
const file = fileInput.files[0];
const expiry = document.getElementById("expiry").value;
const timeValue = document.getElementById("expiryTime").value;
if (!file) {
showAlert("Please choose a file to upload.", "error");
return;
}
try {
const formData = new FormData();
formData.append("file", file);
formData.append("expiry", expiry);
formData.append("expiryTime", timeValue);
// Replace with your actual Upload.io API URL and API key
const apiUrl = "https://api.upload.io/upload"; // Placeholder API URL
const apiKey = "public_G22nhgTDm1B4ZvL1ia7nmepwHaYL"; // Replace with your Upload.io API key
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
},
body: formData,
});
const data = await response.json();
if (data && data.url) {
const fileLink = document.getElementById("fileLink");
fileLink.href = data.url; // Assuming the response contains the file URL
fileLink.textContent = data.url;
document.getElementById("result").style.display = "block";
showAlert("Success!", "success");
} else {
throw new Error("Failed to upload.");
}
} catch (error) {
console.error("Upload failed:", error);
showAlert("Failed to upload.", "error");
}
}
function showAlert(message, type) {
const alertBox = document.getElementById("alert");
alertBox.className = `alert ${type}`;
alertBox.textContent = message;
alertBox.style.display = "block";
}