Files
lash/templates/share.html
2026-05-27 19:00:09 -04:00

79 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lash v{{.Version}}</title>
</head>
<body>
<h1>Enter Token</h1>
<input
type="text"
id="tokenInput"
placeholder="Enter token"
/>
<button id="submitBtn">
Submit
</button>
<p id="status"></p>
<script>
const tokenInput = document.getElementById('tokenInput');
const submitBtn = document.getElementById('submitBtn');
const status = document.getElementById('status');
submitBtn.addEventListener('click', async () => {
const token = tokenInput.value.trim();
if (!token) {
status.textContent = 'Please enter a token.';
return;
}
try {
const response = await fetch('/api/receive-token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ token })
});
if (!response.ok) {
status.textContent = 'Download failed.';
return;
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const disposition = response.headers.get('Content-Disposition');
let filename = 'download.bin';
if (disposition && disposition.includes('filename=')) {
filename = disposition
.split('filename=')[1]
.replace(/"/g, '');
}
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
status.textContent = 'Download started.';
} catch (err) {
console.error(err);
status.textContent = 'An error occurred.';
}
});
</script>
</body>
</html>