From 35cac0db6294e3a327f68a589fea3d92e1032105 Mon Sep 17 00:00:00 2001 From: Cesar Augusto Date: Sun, 24 Nov 2024 00:46:08 -0300 Subject: [PATCH] Don't upload images that were already uploaded elsewhere Users can paste image URLs directly into the editor without triggering uploads. --- .../src/components/Image/ImageEditor.tsx | 9 +++--- .../src/components/Video/VideoEditor.tsx | 9 +++--- src/__tests__/upload.test.ts | 30 +++++++++++++++++++ src/extensions/FileUploadExtension.ts | 3 +- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/examples/react/src/components/Image/ImageEditor.tsx b/examples/react/src/components/Image/ImageEditor.tsx index d8a4359..ec95c59 100644 --- a/examples/react/src/components/Image/ImageEditor.tsx +++ b/examples/react/src/components/Image/ImageEditor.tsx @@ -10,7 +10,8 @@ import { UploadingProgress } from '../UploadingProgress' import { Image } from './Image' export function ImageEditor(props: NodeViewProps) { - const { src, alt, uploadUrl, uploading, uploadError, sha256 } = props.node.attrs as ImageAttributes + const { src, alt, uploadUrl, uploading, uploadError } = props.node.attrs as ImageAttributes + const isUploaded = !src.startsWith('blob://http') return ( - {!sha256 ? props.updateAttributes({ alt })} /> :
} - {!sha256 && ( + {!isUploaded && props.updateAttributes({ alt })} />} + {!isUploaded && ( { @@ -29,7 +30,7 @@ export function ImageEditor(props: NodeViewProps) { }} /> )} - {sha256 && ( + {isUploaded && (