copying attachments WIP

This commit is contained in:
zadam
2023-04-25 00:01:58 +02:00
parent 49fb913eab
commit 330e7ac08e
7 changed files with 50 additions and 11 deletions

View File

@@ -346,7 +346,9 @@ function checkImageAttachments(note, content) {
foundAttachmentIds.add(match[1]);
}
for (const attachment of note.getAttachmentByRole('image')) {
const imageAttachments = note.getAttachmentByRole('image');
for (const attachment of imageAttachments) {
const imageInContent = foundAttachmentIds.has(attachment.attachmentId);
if (attachment.utcDateScheduledForErasureSince && imageInContent) {
@@ -357,6 +359,20 @@ function checkImageAttachments(note, content) {
attachment.save();
}
}
const existingAttachmentIds = new Set(imageAttachments.map(att => att.attachmentId));
const unknownAttachmentIds = Array.from(foundAttachmentIds).filter(foundAttId => !existingAttachmentIds.has(foundAttId));
for (const unknownAttachment of becca.getAttachments(unknownAttachmentIds)) {
// the attachment belongs to a different note (was copy pasted), we need to make a copy for this note.
const newAttachment = unknownAttachment.copy();
newAttachment.parentId = note.noteId;
newAttachment.setContent(unknownAttachment.getContent(), { forceSave: true });
content = content.replace(`api/attachments/${unknownAttachment.attachmentId}/image`, `api/attachments/${newAttachment.attachmentId}/image`);
}
return content;
}
@@ -581,7 +597,7 @@ function saveLinks(note, content) {
content = findInternalLinks(content, foundLinks);
content = findIncludeNoteLinks(content, foundLinks);
checkImageAttachments(note, content);
content = checkImageAttachments(note, content);
}
else if (note.type === 'relationMap') {
findRelationMapLinks(content, foundLinks);