dragdrop: add error handling for URLs

This commit is contained in:
catboxanon 2024-03-16 20:19:12 -04:00 committed by GitHub
parent 83a9dd82db
commit 446cd5a58b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 5 deletions

View File

@ -93,11 +93,20 @@ window.document.addEventListener('drop', async e => {
fileInput.files = files;
fileInput.dispatchEvent(new Event('change'));
} else if (url) {
const request = await fetch(url);
const data = new DataTransfer();
data.items.add(new File([await request.blob()], 'image.png'));
fileInput.files = data.files;
fileInput.dispatchEvent(new Event('change'));
try {
const request = await fetch(url);
if (!request.ok) {
console.error('Error fetching URL:', url, request.status);
return;
}
const data = new DataTransfer();
data.items.add(new File([await request.blob()], 'image.png'));
fileInput.files = data.files;
fileInput.dispatchEvent(new Event('change'));
} catch (error) {
console.error('Error fetching URL:', url, error);
return;
}
}
}