mirror of
https://github.com/milk-net/milk-net.github.io.git
synced 2025-04-19 17:43:42 -05:00
Create script.js
This commit is contained in:
parent
3798bcd836
commit
60090f6f01
1 changed files with 53 additions and 0 deletions
53
host/script.js
Normal file
53
host/script.js
Normal 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";
|
||||
}
|
Loading…
Add table
Reference in a new issue