fix: handle unsupported image upload (#10272)
This commit is contained in:
@@ -40,10 +40,8 @@ export const ImageDropOption = FileDropConfigExtension({
|
|||||||
if (isInsideEdgelessEditor(std.host)) {
|
if (isInsideEdgelessEditor(std.host)) {
|
||||||
const gfx = std.get(GfxControllerIdentifier);
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
point = gfx.viewport.toViewCoordFromClientCoord(point);
|
point = gfx.viewport.toViewCoordFromClientCoord(point);
|
||||||
addImages(std, files, { point, maxWidth: MAX_IMAGE_WIDTH }).catch(
|
addImages(std, files, { point, maxWidth: MAX_IMAGE_WIDTH })
|
||||||
console.error
|
.then(() => {
|
||||||
);
|
|
||||||
|
|
||||||
std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
|
std.getOptional(TelemetryProvider)?.track('CanvasElementAdded', {
|
||||||
control: 'canvas:drop',
|
control: 'canvas:drop',
|
||||||
page: 'whiteboard editor',
|
page: 'whiteboard editor',
|
||||||
@@ -51,6 +49,9 @@ export const ImageDropOption = FileDropConfigExtension({
|
|||||||
segment: 'toolbar',
|
segment: 'toolbar',
|
||||||
type: 'image',
|
type: 'image',
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -512,9 +512,17 @@ export async function addImages(
|
|||||||
// upload image data and update the image model
|
// upload image data and update the image model
|
||||||
const uploadPromises = imageFiles.map(async (file, index) => {
|
const uploadPromises = imageFiles.map(async (file, index) => {
|
||||||
const { point, blockId } = dropInfos[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 sourceId = await std.store.blobSync.set(file);
|
||||||
const imageSize = await readImageSize(file);
|
|
||||||
|
|
||||||
const center = Vec.toVec(point);
|
const center = Vec.toVec(point);
|
||||||
// If maxWidth is provided, limit the width of the image to maxWidth
|
// If maxWidth is provided, limit the width of the image to maxWidth
|
||||||
|
|||||||
Reference in New Issue
Block a user