feat(write): add onImageUpload callback to tiptap editor

This commit is contained in:
xfy 2026-06-05 15:23:36 +08:00
parent c2c7b46958
commit 08bd69d64b

View File

@ -43,6 +43,34 @@ pub fn Write() -> Element {
placeholder: '...',
onUpdate: function(markdown) {
window.__tiptap_content = markdown;
},
onImageUpload: function(file) {
return new Promise(function(resolve, reject) {
var formData = new FormData();
formData.append('image', file);
fetch('/api/upload', {
method: 'POST',
body: formData,
credentials: 'same-origin'
})
.then(function(response) {
if (!response.ok) {
throw new Error('Upload failed: ' + response.status);
}
return response.json();
})
.then(function(data) {
if (data.success && data.url) {
resolve(data.url);
} else {
reject(new Error(data.error || 'Upload failed'));
}
})
.catch(function(err) {
reject(err);
});
});
}
});
window.__tiptap_ready = true;