X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/accf2565a06b05f4db260e761a55d4857404eed2..refs/pull/5689/head:/resources/js/wysiwyg/utils/images.ts diff --git a/resources/js/wysiwyg/utils/images.ts b/resources/js/wysiwyg/utils/images.ts index 89a4a60f0..85bae18e5 100644 --- a/resources/js/wysiwyg/utils/images.ts +++ b/resources/js/wysiwyg/utils/images.ts @@ -1,8 +1,9 @@ import {ImageManager} from "../../components"; -import {$createImageNode} from "../nodes/image"; +import {$createImageNode} from "@lexical/rich-text/LexicalImageNode"; import {$createLinkNode, LinkNode} from "@lexical/link"; -type EditorImageData = { +export type EditorImageData = { + id: string; url: string; thumbs?: {display: string}; name: string; @@ -23,4 +24,21 @@ export function $createLinkedImageNodeFromImageData(image: EditorImageData): Lin }); linkNode.append(imageNode); return linkNode; +} + +/** + * Upload an image file to the server + */ +export async function uploadImageFile(file: File, pageId: string): Promise { + if (file === null || file.type.indexOf('image') !== 0) { + throw new Error('Not an image file'); + } + + const remoteFilename = file.name || `image-${Date.now()}.png`; + const formData = new FormData(); + formData.append('file', file, remoteFilename); + formData.append('uploaded_to', pageId); + + const resp = await window.$http.post('/images/gallery', formData); + return resp.data as EditorImageData; } \ No newline at end of file