update script.js
add functions to download
This commit is contained in:
parent
d37d47080e
commit
526ec305e8
1 changed files with 23 additions and 0 deletions
|
@ -40,3 +40,26 @@ document.getElementById('uploadForm').addEventListener('submit', async function
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
document.getElementById('downloadBtn').addEventListener('click', async function() {
|
||||
const coverLetterText = document.getElementById('coverLetterOutput').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/generate/download', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ coverLetterText })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.downloadLink) {
|
||||
window.location.href = result.downloadLink;
|
||||
} else {
|
||||
alert('Error downloading document.')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
alert('Failed to download document.')
|
||||
}
|
||||
|
||||
});
|
Loading…
Reference in a new issue