From cd27739336858718823c5afaf0fe664b40533f7b Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sat, 25 Nov 2023 13:40:27 +0100 Subject: [PATCH] Upload robustness --- plug-api/silverbullet-syscall/editor.ts | 9 ++++++--- plugs/editor/upload.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plug-api/silverbullet-syscall/editor.ts b/plug-api/silverbullet-syscall/editor.ts index 1a5251a6..4816b62f 100644 --- a/plug-api/silverbullet-syscall/editor.ts +++ b/plug-api/silverbullet-syscall/editor.ts @@ -56,7 +56,10 @@ export function downloadFile(filename: string, dataUrl: string): Promise { return syscall("editor.downloadFile", filename, dataUrl); } -export function uploadFile(accept?: string, capture?: string): Promise { +export function uploadFile( + accept?: string, + capture?: string, +): Promise { return syscall("editor.uploadFile", accept, capture); } @@ -77,7 +80,7 @@ export function filterBox( } export function showPanel( - id: "lhs" | "rhs" | "bhs" | "modal" | "ps", + id: "lhs" | "rhs" | "bhs" | "modal" | "ps" | "preface", mode: number, html: string, script = "", @@ -86,7 +89,7 @@ export function showPanel( } export function hidePanel( - id: "lhs" | "rhs" | "bhs" | "modal" | "ps", + id: "lhs" | "rhs" | "bhs" | "modal" | "ps" | "preface", ): Promise { return syscall("editor.hidePanel", id); } diff --git a/plugs/editor/upload.ts b/plugs/editor/upload.ts index 1fb4838b..37c215d5 100644 --- a/plugs/editor/upload.ts +++ b/plugs/editor/upload.ts @@ -37,7 +37,7 @@ async function saveFile(file: UploadFile) { file.content, ); let attachmentMarkdown = `[${finalFileName}](${encodeURI(finalFileName)})`; - if (file.contentType.startsWith("image/")) { + if (file.contentType?.startsWith("image/")) { attachmentMarkdown = `![](${encodeURI(finalFileName)})`; } editor.insertAtCursor(attachmentMarkdown);