mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
use widely available arrayBuffer
* stream fails in safari
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { imageDimensionsFromStream } from "image-dimensions";
|
import { imageDimensionsFromData } from 'image-dimensions';
|
||||||
import { MediaUploadOptions, UploadFn } from "../media-utils";
|
import { MediaUploadOptions, UploadFn } from '../media-utils';
|
||||||
import { IAttachment } from "../types";
|
import { IAttachment } from '../types';
|
||||||
import { generateNodeId } from "../utils";
|
import { generateNodeId } from '../utils';
|
||||||
import { Node } from "@tiptap/pm/model";
|
import { Node } from '@tiptap/pm/model';
|
||||||
import { Command } from "@tiptap/core";
|
import { Command } from '@tiptap/core';
|
||||||
|
|
||||||
const findImageNodeByPlaceholderId = (
|
const findImageNodeByPlaceholderId = (
|
||||||
doc: Node,
|
doc: Node,
|
||||||
@@ -14,7 +14,7 @@ const findImageNodeByPlaceholderId = (
|
|||||||
doc.descendants((node, pos) => {
|
doc.descendants((node, pos) => {
|
||||||
if (result) return false;
|
if (result) return false;
|
||||||
if (
|
if (
|
||||||
node.type.name === "image" &&
|
node.type.name === 'image' &&
|
||||||
node.attrs.placeholder?.id === placeholderId
|
node.attrs.placeholder?.id === placeholderId
|
||||||
) {
|
) {
|
||||||
result = { node, pos };
|
result = { node, pos };
|
||||||
@@ -34,7 +34,11 @@ const handleImageUpload =
|
|||||||
if (!validated) return;
|
if (!validated) return;
|
||||||
|
|
||||||
const objectUrl = URL.createObjectURL(file);
|
const objectUrl = URL.createObjectURL(file);
|
||||||
const imageDimensions = await imageDimensionsFromStream(file.stream());
|
|
||||||
|
const imageDimensions = imageDimensionsFromData(
|
||||||
|
new Uint8Array(await file.arrayBuffer()),
|
||||||
|
);
|
||||||
|
|
||||||
const placeholderId = generateNodeId();
|
const placeholderId = generateNodeId();
|
||||||
const aspectRatio = imageDimensions
|
const aspectRatio = imageDimensions
|
||||||
? imageDimensions.width / imageDimensions.height
|
? imageDimensions.width / imageDimensions.height
|
||||||
|
|||||||
Reference in New Issue
Block a user