import and export fixes

This commit is contained in:
zadam
2023-07-13 23:54:47 +02:00
parent a748710b01
commit ca41806bc2
6 changed files with 621 additions and 55 deletions

View File

@@ -65,6 +65,23 @@ function exportSingleNote(taskContext, branch, format, res) {
}
function inlineAttachments(content) {
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/?[^"]+"/g, (match, noteId) => {
const note = becca.getNote(noteId);
if (!note || !note.mime.startsWith('image/')) {
return match;
}
const imageContent = note.getContent();
if (!Buffer.isBuffer(imageContent)) {
return match;
}
const base64Content = imageContent.toString('base64');
const srcValue = `data:${note.mime};base64,${base64Content}`;
return `src="${srcValue}"`;
});
content = content.replace(/src="[^"]*api\/attachments\/([a-zA-Z0-9_]+)\/image\/?[^"]+"/g, (match, attachmentId) => {
const attachment = becca.getAttachment(attachmentId);
if (!attachment || !attachment.mime.startsWith('image/')) {