diff --git a/frontend/apps/desktop/src/main.ts b/frontend/apps/desktop/src/main.ts index fc014aa1a..f6f75cd9f 100644 --- a/frontend/apps/desktop/src/main.ts +++ b/frontend/apps/desktop/src/main.ts @@ -147,7 +147,7 @@ ipcMain.on( title: string markdown: { markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] } }[], ) => { @@ -214,9 +214,11 @@ ipcMain.on( const uploadMediaFile = async ({ url, filename, + placeholder, }: { url: string filename: string + placeholder: string }) => { return new Promise((resolve, reject) => { const regex = /ipfs:\/\/(.+)/ @@ -252,7 +254,7 @@ ipcMain.on( debug(`Media file successfully saved: ${mediaFilePath}`) // Update the markdown content with the correct file name updatedMarkdownContent = updatedMarkdownContent.replace( - filename, + placeholder, filenameWithExt, ) resolve() diff --git a/frontend/apps/desktop/src/preload.ts b/frontend/apps/desktop/src/preload.ts index 0f90f6da0..18f939569 100644 --- a/frontend/apps/desktop/src/preload.ts +++ b/frontend/apps/desktop/src/preload.ts @@ -50,7 +50,7 @@ contextBridge.exposeInMainWorld('docExport', { exportDocument: async ( title: string, markdownContent: string, - mediaFiles: {url: string; filename: string}[], + mediaFiles: {url: string; filename: string; placeholder: string}[], ) => { return new Promise((resolve, reject) => { ipcRenderer.once('export-completed', (event, response) => { @@ -70,7 +70,7 @@ contextBridge.exposeInMainWorld('docExport', { title: string markdown: { markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] } }[], ) => { diff --git a/frontend/apps/desktop/src/root.tsx b/frontend/apps/desktop/src/root.tsx index 843101ae7..058d7094c 100644 --- a/frontend/apps/desktop/src/root.tsx +++ b/frontend/apps/desktop/src/root.tsx @@ -243,7 +243,7 @@ function MainApp({ exportDocument={async ( title: string, markdownContent: string, - mediaFiles: {url: string; filename: string}[], + mediaFiles: {url: string; filename: string; placeholder: string}[], ) => { // @ts-ignore return window.docExport.exportDocument( @@ -257,7 +257,7 @@ function MainApp({ title: string markdown: { markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] } }[], ) => { diff --git a/frontend/apps/desktop/src/save-markdown-file.tsx b/frontend/apps/desktop/src/save-markdown-file.tsx index 047605e03..15704f16d 100644 --- a/frontend/apps/desktop/src/save-markdown-file.tsx +++ b/frontend/apps/desktop/src/save-markdown-file.tsx @@ -11,7 +11,7 @@ export async function saveMarkdownFile( args: { title: string markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] }, ) { const {title, markdownContent, mediaFiles} = args @@ -51,9 +51,11 @@ export async function saveMarkdownFile( const uploadMediaFile = ({ url, filename, + placeholder, }: { url: string filename: string + placeholder: string }) => { return new Promise((resolve, reject) => { const regex = /ipfs:\/\/(.+)/ @@ -87,7 +89,7 @@ export async function saveMarkdownFile( debug(`Media file successfully saved: ${mediaFilePath}`) // Update the markdown content with the correct file name updatedMarkdownContent = updatedMarkdownContent.replace( - filename, + placeholder, filenameWithExt, ) resolve() diff --git a/frontend/packages/app/app-context.tsx b/frontend/packages/app/app-context.tsx index db229102f..f3508dc3d 100644 --- a/frontend/packages/app/app-context.tsx +++ b/frontend/packages/app/app-context.tsx @@ -23,14 +23,14 @@ export type AppContext = { exportDocument: ( title: string, markdownContent: string, - mediaFiles: {url: string; filename: string}[], + mediaFiles: {url: string; filename: string; placeholder: string}[], ) => Promise exportDocuments: ( documents: { title: string markdown: { markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] } }[], ) => Promise @@ -64,14 +64,14 @@ export function AppContextProvider({ exportDocument: ( title: string, markdownContent: string, - mediaFiles: {url: string; filename: string}[], + mediaFiles: {url: string; filename: string; placeholder: string}[], ) => Promise exportDocuments: ( documents: { title: string markdown: { markdownContent: string - mediaFiles: {url: string; filename: string}[] + mediaFiles: {url: string; filename: string; placeholder: string}[] } }[], ) => Promise diff --git a/frontend/packages/app/utils/blocks-to-markdown.ts b/frontend/packages/app/utils/blocks-to-markdown.ts index b46f63eb0..7a32009a0 100644 --- a/frontend/packages/app/utils/blocks-to-markdown.ts +++ b/frontend/packages/app/utils/blocks-to-markdown.ts @@ -114,7 +114,8 @@ function convertBlocksToHtml( } async function extractMediaFiles(blocks: HMBlock[]) { - const mediaFiles: {url: string; filename: string}[] = [] + const mediaFiles: {url: string; filename: string; placeholder: string}[] = [] + let counter = 1 const extractMedia = async (block) => { if ( block.type === 'image' || @@ -131,8 +132,10 @@ async function extractMediaFiles(blocks: HMBlock[]) { return } const filename = url.split('/').pop() - mediaFiles.push({url, filename}) - block.props = {...block.props, url: `media/${filename}`} // Update the URL to point to the local media folder + const placeholder = `file-${counter}` + mediaFiles.push({url, filename, placeholder}) + counter++ + block.props = {...block.props, url: `media/${placeholder}`} // Update the URL to point to the local media folder } } if (block.children) {