|
|
<!DOCTYPE html> |
|
|
<html lang="en"> |
|
|
<head> |
|
|
<meta charset="UTF-8"> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<title>Upload File</title> |
|
|
<style> |
|
|
body { |
|
|
font-family: Arial, sans-serif; |
|
|
max-width: 600px; |
|
|
margin: 0 auto; |
|
|
padding: 20px; |
|
|
background-color: #f5f5f5; |
|
|
} |
|
|
.container { |
|
|
background-color: white; |
|
|
padding: 30px; |
|
|
border-radius: 8px; |
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
|
|
} |
|
|
h1 { |
|
|
color: #25D366; |
|
|
text-align: center; |
|
|
} |
|
|
.form-group { |
|
|
margin-bottom: 20px; |
|
|
} |
|
|
label { |
|
|
display: block; |
|
|
margin-bottom: 5px; |
|
|
font-weight: bold; |
|
|
} |
|
|
input[type="file"] { |
|
|
width: 100%; |
|
|
padding: 10px; |
|
|
border: 1px solid #ddd; |
|
|
border-radius: 4px; |
|
|
} |
|
|
button { |
|
|
background-color: #25D366; |
|
|
color: white; |
|
|
border: none; |
|
|
padding: 10px 20px; |
|
|
border-radius: 4px; |
|
|
cursor: pointer; |
|
|
} |
|
|
button:hover { |
|
|
background-color: #128C7E; |
|
|
} |
|
|
#result { |
|
|
margin-top: 20px; |
|
|
padding: 10px; |
|
|
border-radius: 4px; |
|
|
} |
|
|
.success { |
|
|
background-color: #d4edda; |
|
|
color: #155724; |
|
|
} |
|
|
.error { |
|
|
background-color: #f8d7da; |
|
|
color: #721c24; |
|
|
} |
|
|
.back-link { |
|
|
display: block; |
|
|
margin-top: 20px; |
|
|
text-align: center; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<div class="container"> |
|
|
<h1>Upload File for WhatsApp Bot</h1> |
|
|
|
|
|
<form id="uploadForm"> |
|
|
<div class="form-group"> |
|
|
<label for="file">Select file to upload:</label> |
|
|
<input type="file" id="file" name="file" required> |
|
|
</div> |
|
|
<button type="submit">Upload</button> |
|
|
</form> |
|
|
|
|
|
<div id="result"></div> |
|
|
|
|
|
<a href="/" class="back-link">β Back to Home</a> |
|
|
</div> |
|
|
|
|
|
<script> |
|
|
document.getElementById('uploadForm').addEventListener('submit', async (e) => { |
|
|
e.preventDefault(); |
|
|
|
|
|
const fileInput = document.getElementById('file'); |
|
|
const resultDiv = document.getElementById('result'); |
|
|
|
|
|
if (fileInput.files.length === 0) { |
|
|
resultDiv.className = 'error'; |
|
|
resultDiv.textContent = 'Please select a file to upload'; |
|
|
return; |
|
|
} |
|
|
|
|
|
const formData = new FormData(); |
|
|
formData.append('file', fileInput.files[0]); |
|
|
|
|
|
try { |
|
|
const response = await fetch('/api/upload', { |
|
|
method: 'POST', |
|
|
body: formData |
|
|
}); |
|
|
|
|
|
const data = await response.json(); |
|
|
|
|
|
if (response.ok) { |
|
|
resultDiv.className = 'success'; |
|
|
resultDiv.innerHTML = ` |
|
|
<p>File uploaded successfully!</p> |
|
|
<p><strong>Original Name:</strong> ${data.file.originalName}</p> |
|
|
<p><strong>File Name:</strong> ${data.file.fileName}</p> |
|
|
<p><strong>Size:</strong> ${(data.file.size / 1024).toFixed(2)} KB</p> |
|
|
<p><strong>URL:</strong> <a href="${data.file.url}" target="_blank">${data.file.url}</a></p> |
|
|
`; |
|
|
} else { |
|
|
throw new Error(data.error || 'Failed to upload file'); |
|
|
} |
|
|
} catch (error) { |
|
|
resultDiv.className = 'error'; |
|
|
resultDiv.textContent = `Error: ${error.message}`; |
|
|
} |
|
|
}); |
|
|
</script> |
|
|
</body> |
|
|
</html> |