From 1ba38ca40df881bbbe28072887f0743d4f90eb1b Mon Sep 17 00:00:00 2001 From: kptdobe Date: Thu, 2 Oct 2025 11:48:46 +0200 Subject: [PATCH 1/3] feat: use media route --- blocks/edit/prose/plugins/imageDrop.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/blocks/edit/prose/plugins/imageDrop.js b/blocks/edit/prose/plugins/imageDrop.js index 527c21757..b332b0f8e 100644 --- a/blocks/edit/prose/plugins/imageDrop.js +++ b/blocks/edit/prose/plugins/imageDrop.js @@ -25,11 +25,11 @@ export default function imageDrop(schema) { const { $from } = view.state.selection; const details = getPathDetails(); - const url = `${details.origin}/source${details.parent}/.${details.name}/${file.name}`; + const url = `${details.origin}/media${details.parent}/${file.name}`; const formData = new FormData(); formData.append('data', file); - const opts = { method: 'PUT', body: formData }; + const opts = { method: 'POST', body: formData }; const resp = await daFetch(url, opts); if (!resp.ok) return; const json = await resp.json(); @@ -39,11 +39,11 @@ export default function imageDrop(schema) { docImg.addEventListener('load', () => { const fpoSelection = TextSelection.create(view.state.doc, $from.pos - 1, $from.pos); const ts = view.state.tr.setSelection(fpoSelection); - const img = schema.nodes.image.create({ src: json.source.contentUrl }); + const img = schema.nodes.image.create({ src: json.uri }); const tr = ts.replaceSelectionWith(img).scrollIntoView(); view.dispatch(tr); }); - docImg.src = json.source.contentUrl; + docImg.src = json.uri; }); }, }, From 8a147d5b5ff73716da4027be1301c071c5ec4555 Mon Sep 17 00:00:00 2001 From: kptdobe Date: Thu, 2 Oct 2025 15:47:29 +0200 Subject: [PATCH 2/3] feat: show dialog in case of error --- blocks/edit/prose/plugins/imageDrop.js | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/blocks/edit/prose/plugins/imageDrop.js b/blocks/edit/prose/plugins/imageDrop.js index b332b0f8e..afe00a170 100644 --- a/blocks/edit/prose/plugins/imageDrop.js +++ b/blocks/edit/prose/plugins/imageDrop.js @@ -6,6 +6,21 @@ import { daFetch } from '../../../shared/utils.js'; const FPO_IMG_URL = 'https://content.da.live/auniverseaway/da/assets/fpo.svg'; const SUPPORTED_FILES = ['image/svg+xml', 'image/png', 'image/jpeg', 'image/gif']; +async function renderError(message) { + await import('../../../shared/da-dialog/da-dialog.js'); + const dialog = document.createElement('da-dialog'); + dialog.title = 'Error'; + dialog.message = message; + dialog.action = { + style: 'accent', + label: 'OK', + click: async () => { dialog.close(); }, + }; + const main = document.body.querySelector('main'); + main.insertAdjacentElement('afterend', dialog); + dialog.showModal(); +} + export default function imageDrop(schema) { return new Plugin({ props: { @@ -31,7 +46,19 @@ export default function imageDrop(schema) { formData.append('data', file); const opts = { method: 'POST', body: formData }; const resp = await daFetch(url, opts); - if (!resp.ok) return; + if (!resp.ok) { + const fpoSelection = TextSelection.create(view.state.doc, $from.pos - 1, $from.pos); + const ts = view.state.tr.setSelection(fpoSelection); + view.dispatch(ts.deleteSelection().scrollIntoView()); + + if (resp.status === 413) { + renderError('Image size exceeds 20MB limit'); + } else { + renderError(`Failed to upload image: ${resp.statusText}`); + } + + return; + } const json = await resp.json(); // Create a doc image to pre-download the image before showing it. From 6b534d0fa8c5d1fbc64d241fcdf28975c90d13d5 Mon Sep 17 00:00:00 2001 From: kptdobe Date: Thu, 5 Mar 2026 10:36:49 +0100 Subject: [PATCH 3/3] chore: error handling --- blocks/edit/prose/plugins/imageDrop.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blocks/edit/prose/plugins/imageDrop.js b/blocks/edit/prose/plugins/imageDrop.js index 44603eaaa..31543eeb6 100644 --- a/blocks/edit/prose/plugins/imageDrop.js +++ b/blocks/edit/prose/plugins/imageDrop.js @@ -54,7 +54,12 @@ export default function imageDrop(schema) { if (resp.status === 413) { renderError('Image size exceeds 20MB limit'); } else { - renderError(`Failed to upload image: ${resp.statusText}`); + const json = await resp.json(); + if (json.error) { + renderError(`Failed to upload image: ${json.error}`); + } else { + renderError(`Failed to upload image: ${json.message}`); + } } return;