Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixes for image download
zadam2369bcf9fcf5
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xmlindex a9dfc5250f..70caa7f2a0 100644--- a/.idea/dataSources.xml+++ b/.idea/dataSources.xml@@ -1,25 +1,11 @@<?xml version="1.0" encoding="UTF-8"?><project version="4"><component name="DataSourceManagerImpl" format="xml" multifile-model="true">- <data-source source="LOCAL" name="document.db" uuid="a2c75661-f9e2-478f-a69f-6a9409e69997">+ <data-source source="LOCAL" name="SQLite - document.db" uuid="d0fd879f-1e1d-4d5c-9c21-0e5cf9ab2976"><driver-ref>sqlite.xerial</driver-ref><synchronize>true</synchronize><jdbc-driver>org.sqlite.JDBC</jdbc-driver>- <jdbc-url>jdbc:sqlite:$USER_HOME$/trilium-data/document.db</jdbc-url>- </data-source>- <data-source source="LOCAL" name="document" uuid="066dc5f4-4097-429e-8cf1-3adc0a9d648a">- <driver-ref>sqlite.xerial</driver-ref>- <synchronize>true</synchronize>- <jdbc-driver>org.sqlite.JDBC</jdbc-driver>- <jdbc-url>jdbc:sqlite:$PROJECT_DIR$/dist/trilium linux x64/trilium-data/document.db</jdbc-url>- <libraries>- <library>- <url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/xerial-sqlite-license.txt</url>- </library>- <library>- <url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/sqlite-jdbc-3.16.1.jar</url>- </library>- </libraries>+ <jdbc-url>jdbc:sqlite:$PROJECT_DIR$/../trilium-data/document.db</jdbc-url></data-source></component></project>\ No newline at end of filediff --git a/src/services/attributes.js b/src/services/attributes.jsindex d1abd7cecc..bab322cbde 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -19,6 +19,7 @@ const BUILTIN_ATTRIBUTES = [{ type: 'label', name: 'appTheme' },{ type: 'label', name: 'hidePromotedAttributes' },{ type: 'label', name: 'readOnly' },+ { type: 'label', name: 'autoReadOnlyDisabled' },{ type: 'label', name: 'cssClass' },{ type: 'label', name: 'iconClass' },{ type: 'label', name: 'keyboardShortcut' },diff --git a/src/services/notes.js b/src/services/notes.jsindex 4df9846e83..152c72ec48 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -293,15 +293,11 @@ async function downloadImages(noteId, content) {if (!url.includes('api/images/')// this is and exception for the web clipper's "imageId"&& (url.length !== 20 || url.toLowerCase().startsWith('http'))) {- if (url in downloadImagePromises) {- // download is already in progress- continue;- }if (url in imageUrlToNoteIdMapping) {const imageNote = await repository.getNote(imageUrlToNoteIdMapping[url]);- if (imageNote || imageNote.isDeleted) {+ if (!imageNote || imageNote.isDeleted) {delete imageUrlToNoteIdMapping[url];}else {@@ -322,6 +318,11 @@ async function downloadImages(noteId, content) {continue;}+ if (url in downloadImagePromises) {+ // download is already in progress+ continue;+ }+// this is done asynchronously, it would be too slow to wait for the download// given that save can be triggered very oftendownloadImagePromises[url] = downloadImage(noteId, url);@@ -338,28 +339,30 @@ async function downloadImages(noteId, content) {// are downloaded and the IMG references are not updated. For this occassion we have this code// which upon the download of all the images will update the note if the links have not been fixed before- const imageNotes = await repository.getNotes(Object.values(imageUrlToNoteIdMapping));+ await sql.transactional(async () => {+ const imageNotes = await repository.getNotes(Object.values(imageUrlToNoteIdMapping));- const origNote = await repository.getNote(noteId);- const origContent = await origNote.getContent();- let updatedContent = origContent;+ const origNote = await repository.getNote(noteId);+ const origContent = await origNote.getContent();+ let updatedContent = origContent;- for (const url in imageUrlToNoteIdMapping) {- const imageNote = imageNotes.find(note => note.noteId === imageUrlToNoteIdMapping[url]);+ for (const url in imageUrlToNoteIdMapping) {+ const imageNote = imageNotes.find(note => note.noteId === imageUrlToNoteIdMapping[url]);- if (imageNote && !imageNote.isDeleted) {- updatedContent = replaceUrl(updatedContent, url, imageNote);+ if (imageNote && !imageNote.isDeleted) {+ updatedContent = replaceUrl(updatedContent, url, imageNote);+ }}- }- // update only if the links have not been already fixed.- if (updatedContent !== origContent) {- await origNote.setContent(updatedContent);+ // update only if the links have not been already fixed.+ if (updatedContent !== origContent) {+ await origNote.setContent(updatedContent);- await scanForLinks(origNote);+ await scanForLinks(origNote);- console.log(`Fixed the image links for note ${noteId} to the offline saved.`);- }+ console.log(`Fixed the image links for note ${noteId} to the offline saved.`);+ }+ });}, 5000);});