mirror of
https://github.com/docmost/docmost.git
synced 2026-05-11 00:44:07 +08:00
fix local attachment paths in exports (#1013)
This commit is contained in:
@@ -62,17 +62,30 @@ export function isAttachmentNode(nodeType: string) {
|
||||
return attachmentNodeTypes.includes(nodeType);
|
||||
}
|
||||
|
||||
export function updateAttachmentUrls(prosemirrorJson: any) {
|
||||
export function updateAttachmentUrlsToLocalPaths(prosemirrorJson: any) {
|
||||
const doc = jsonToNode(prosemirrorJson);
|
||||
if (!doc) return null;
|
||||
|
||||
// Helper function to replace specific URL prefixes
|
||||
const replacePrefix = (url: string): string => {
|
||||
const prefixes = ['/files', '/api/files'];
|
||||
for (const prefix of prefixes) {
|
||||
if (url.startsWith(prefix)) {
|
||||
return url.replace(prefix, 'files');
|
||||
}
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
doc?.descendants((node: Node) => {
|
||||
if (isAttachmentNode(node.type.name)) {
|
||||
if (node.attrs.src && node.attrs.src.startsWith('/files')) {
|
||||
//@ts-expect-error
|
||||
node.attrs.src = node.attrs.src.replace('/files', 'files');
|
||||
} else if (node.attrs.url && node.attrs.url.startsWith('/files')) {
|
||||
//@ts-expect-error
|
||||
node.attrs.url = node.attrs.url.replace('/files', 'files');
|
||||
if (node.attrs.src) {
|
||||
// @ts-ignore
|
||||
node.attrs.src = replacePrefix(node.attrs.src);
|
||||
}
|
||||
if (node.attrs.url) {
|
||||
// @ts-ignore
|
||||
node.attrs.url = replacePrefix(node.attrs.url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user