Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: handle unsupported image upload (#10272)

dooudingdad39d11298b
diff --git a/blocksuite/affine/block-image/src/image-service.ts b/blocksuite/affine/block-image/src/image-service.ts
index 4d63cd7684..962c5bb285 100644
--- a/blocksuite/affine/block-image/src/image-service.ts
+++ b/blocksuite/affine/block-image/src/image-service.ts
@@ -40,17 +40,18 @@ export const ImageDropOption = FileDropConfigExtension({
if (isInsideEdgelessEditor(std.host)) {
const gfx = std.get(GfxControllerIdentifier);
point = gfx.viewport.toViewCoordFromClientCoord(point);
- addImages(std, files, { point, maxWidth: MAX_IMAGE_WIDTH }).catch(
- console.error
- );
+ addImages(std, files, { point, maxWidth: MAX_IMAGE_WIDTH })
+ .then(() => {
+ std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
+ control: 'canvas:drop',
+ page: 'whiteboard editor',
+ module: 'toolbar',
+ segment: 'toolbar',
+ type: 'image',
+ });
+ })
+ .catch(console.error);
- std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
- control: 'canvas:drop',
- page: 'whiteboard editor',
- module: 'toolbar',
- segment: 'toolbar',
- type: 'image',
- });
return true;
}
diff --git a/blocksuite/affine/block-image/src/utils.ts b/blocksuite/affine/block-image/src/utils.ts
index eb5d43027c..9719cb70bf 100644
--- a/blocksuite/affine/block-image/src/utils.ts
+++ b/blocksuite/affine/block-image/src/utils.ts
@@ -512,9 +512,17 @@ export async function addImages(
// upload image data and update the image model
const uploadPromises = imageFiles.map(async (file, index) => {
const { point, blockId } = dropInfos[index];
+ const block = std.store.getBlock(blockId);
+ const imageSize = await readImageSize(file);
+
+ if (!imageSize.width || !imageSize.height) {
+ std.store.deleteBlock(block!.model);
+
+ toast(std.host, 'Failed to read image size, please try another image');
+ throw new Error('Failed to read image size');
+ }
const sourceId = await std.store.blobSync.set(file);
- const imageSize = await readImageSize(file);
const center = Vec.toVec(point);
// If maxWidth is provided, limit the width of the image to maxWidth