les images s'hébergent correctement
This commit is contained in:
parent
f909a48b92
commit
65f8f03fc0
@ -49,11 +49,41 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
['clean']
|
['clean']
|
||||||
],
|
],
|
||||||
handlers: {
|
handlers: {
|
||||||
'divider': function() {
|
image: function() {
|
||||||
const range = quill.getSelection(true);
|
const input = document.createElement('input');
|
||||||
quill.insertText(range.index, '\n', Quill.sources.USER);
|
input.setAttribute('type', 'file');
|
||||||
quill.insertEmbed(range.index + 1, 'divider', true, Quill.sources.USER);
|
input.setAttribute('accept', 'image/*');
|
||||||
quill.setSelection(range.index + 2, Quill.sources.SILENT);
|
input.click();
|
||||||
|
|
||||||
|
input.onchange = async () => {
|
||||||
|
const file = input.files[0];
|
||||||
|
if (file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('image', file);
|
||||||
|
formData.append('storyId', storyId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('api/upload-image.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error('Upload failed');
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
if (result.success) {
|
||||||
|
const range = quill.getSelection(true);
|
||||||
|
quill.insertEmbed(range.index, 'image', result.url);
|
||||||
|
quill.setSelection(range.index + 1);
|
||||||
|
} else {
|
||||||
|
showNotification(result.error || 'Erreur lors de l\'upload', 'error');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
showNotification('Erreur lors de l\'upload de l\'image', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user