From cd19d455a419e07800fcc86f03f7843010650c94 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 19 Dec 2023 18:59:12 +0100 Subject: [PATCH] More #363 work, relative paths for attachments when uploading --- plugs/editor/upload.ts | 7 +++---- web/cm_plugins/editor_paste.ts | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/plugs/editor/upload.ts b/plugs/editor/upload.ts index ad7cd636..04d0fd80 100644 --- a/plugs/editor/upload.ts +++ b/plugs/editor/upload.ts @@ -23,17 +23,16 @@ async function saveFile(file: UploadFile) { // root folder case prefix = ""; } - const suggestedName = prefix + file.name; const finalFileName = await editor.prompt( "File name for pasted attachment", - suggestedName, + file.name, ); if (!finalFileName) { return; } await space.writeAttachment( - finalFileName, + prefix + finalFileName, file.content, ); let attachmentMarkdown = `[${finalFileName}](${encodeURI(finalFileName)})`; @@ -46,4 +45,4 @@ async function saveFile(file: UploadFile) { export async function uploadFile(_ctx: any, accept?: string, capture?: string) { const uploadFile = await editor.uploadFile(accept, capture); await saveFile(uploadFile); -} \ No newline at end of file +} diff --git a/web/cm_plugins/editor_paste.ts b/web/cm_plugins/editor_paste.ts index 5666dbd5..a42a15e9 100644 --- a/web/cm_plugins/editor_paste.ts +++ b/web/cm_plugins/editor_paste.ts @@ -204,8 +204,6 @@ export function attachmentExtension(editor: Client) { return; } - suggestedName = resolve(folderName(editor.currentPage!), suggestedName); - const finalFileName = await editor.prompt( "File name for pasted attachment", suggestedName, @@ -214,7 +212,7 @@ export function attachmentExtension(editor: Client) { return; } await editor.space.writeAttachment( - finalFileName, + resolve(folderName(editor.currentPage!), finalFileName), new Uint8Array(data), ); let attachmentMarkdown = `[${finalFileName}](${encodeURI(finalFileName)})`;