File tree Expand file tree Collapse file tree
apps/server/src/integrations/export Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import {
2121 getProsemirrorContent ,
2222 PageExportTree ,
2323 replaceInternalLinks ,
24- updateAttachmentUrls ,
24+ updateAttachmentUrlsToLocalPaths ,
2525} from './utils' ;
2626import { PageRepo } from '@docmost/db/repos/page/page.repo' ;
2727import { Node } from '@tiptap/pm/model' ;
@@ -193,7 +193,7 @@ export class ExportService {
193193
194194 if ( includeAttachments ) {
195195 await this . zipAttachments ( updatedJsonContent , page . spaceId , folder ) ;
196- updatedJsonContent = updateAttachmentUrls ( updatedJsonContent ) ;
196+ updatedJsonContent = updateAttachmentUrlsToLocalPaths ( updatedJsonContent ) ;
197197 }
198198
199199 const pageTitle = getPageTitle ( page . title ) ;
Original file line number Diff line number Diff line change @@ -62,17 +62,30 @@ export function isAttachmentNode(nodeType: string) {
6262 return attachmentNodeTypes . includes ( nodeType ) ;
6363}
6464
65- export function updateAttachmentUrls ( prosemirrorJson : any ) {
65+ export function updateAttachmentUrlsToLocalPaths ( prosemirrorJson : any ) {
6666 const doc = jsonToNode ( prosemirrorJson ) ;
67+ if ( ! doc ) return null ;
68+
69+ // Helper function to replace specific URL prefixes
70+ const replacePrefix = ( url : string ) : string => {
71+ const prefixes = [ '/files' , '/api/files' ] ;
72+ for ( const prefix of prefixes ) {
73+ if ( url . startsWith ( prefix ) ) {
74+ return url . replace ( prefix , 'files' ) ;
75+ }
76+ }
77+ return url ;
78+ } ;
6779
6880 doc ?. descendants ( ( node : Node ) => {
6981 if ( isAttachmentNode ( node . type . name ) ) {
70- if ( node . attrs . src && node . attrs . src . startsWith ( '/files' ) ) {
71- //@ts -expect-error
72- node . attrs . src = node . attrs . src . replace ( '/files' , 'files' ) ;
73- } else if ( node . attrs . url && node . attrs . url . startsWith ( '/files' ) ) {
74- //@ts -expect-error
75- node . attrs . url = node . attrs . url . replace ( '/files' , 'files' ) ;
82+ if ( node . attrs . src ) {
83+ // @ts -ignore
84+ node . attrs . src = replacePrefix ( node . attrs . src ) ;
85+ }
86+ if ( node . attrs . url ) {
87+ // @ts -ignore
88+ node . attrs . url = replacePrefix ( node . attrs . url ) ;
7689 }
7790 }
7891 } ) ;
You can’t perform that action at this time.
0 commit comments