Обработчик скачивания лицензии
This commit is contained in:
32
frontend/js/main.js
Normal file
32
frontend/js/main.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const form = document.getElementById('licenseForm');
|
||||
const status = document.getElementById('status');
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
status.textContent = "Генерация лицензии...";
|
||||
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/generate', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(`Ошибка: ${response.statusText}`);
|
||||
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `Custom.mxtpro`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
|
||||
status.textContent = "Лицензия успешно сгенерирована!";
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
status.textContent = "Ошибка генерации лицензии.";
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user