Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix import featured images - EXO-74718 - Meeds-io/meeds#2499 #1171

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;

Expand Down Expand Up @@ -1341,7 +1342,8 @@ public void importNotes(List<String> files, Page parent, String conflict, Identi
notesFilePath = file;
}
if (file.contains("/" + FEATURED_IMAGE_FOLDER + "/")) {
String imageId = file.substring(file.lastIndexOf("/") + 1);
String fileName = file.substring(file.lastIndexOf("/") + 1);
String imageId = fileName.substring(0, fileName.lastIndexOf("."));
featuredImages.put(imageId, file);
}
}
Expand Down Expand Up @@ -1975,6 +1977,7 @@ private void importNote(Page note,
String conflict,
Identity userIdentity) throws Exception {

Page targetNote = null;
File featuredImageFile = extractNoteFeaturedImageFileToImport(note, featuredImages);
Page parent_ = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), parent.getName());
if (parent_ == null) {
Expand All @@ -1991,6 +1994,7 @@ private void importNote(Page note,
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);
targetNote = note_;
} else {
if (StringUtils.isNotEmpty(conflict)) {
if (conflict.equals("overwrite") || conflict.equals("replaceAll")) {
Expand All @@ -2000,24 +2004,27 @@ private void importNote(Page note,
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);

targetNote = note_;
}
if (conflict.equals("duplicate")) {
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity);
targetNote = note_;
}
if (conflict.equals("update")) {
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())) {
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())
|| !Objects.equals(note_2.getProperties(), note.getProperties())) {
note_2.setTitle(note.getTitle());
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note_2.setContent(processedContent);
note_2 = updateNote(note_2, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
createVersionOfNote(note_2, userIdentity.getUserId());
targetNote = note_2;
}
}
}
Expand All @@ -2026,20 +2033,21 @@ private void importNote(Page note,
if (StringUtils.isNotEmpty(conflict)
&& (conflict.equals("update") || conflict.equals("overwrite") || conflict.equals("replaceAll"))) {
Page note_1 = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), note.getName());
if (!note.getContent().equals(note_1.getContent())) {
if (!note.getContent().equals(note_1.getContent()) || !Objects.equals(note_1.getProperties(), note.getProperties())) {
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note.setContent(processedContent);
note_1.setContent(processedContent);
note_1 = updateNote(note_1, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
createVersionOfNote(note_1, userIdentity.getUserId());
targetNote = note_1;
}
}
}
if (featuredImageFile != null) {
saveImportedFeaturedImage(featuredImageFile,
note,
targetNote,
Long.parseLong(identityManager.getOrCreateUserIdentity(userIdentity.getUserId()).getId()));
}
if (note.getChildren() != null) {
Expand Down