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
added "explodeArchives" option to the import dialog
zadam8b3e72102817
diff --git a/src/public/javascripts/dialogs/import.js b/src/public/javascripts/dialogs/import.jsindex 4de525d872..267517923b 100644--- a/src/public/javascripts/dialogs/import.js+++ b/src/public/javascripts/dialogs/import.js@@ -16,6 +16,7 @@ const $safeImportCheckbox = $("#safe-import-checkbox");const $shrinkImagesCheckbox = $("#shrink-images-checkbox");const $textImportedAsTextCheckbox = $("#text-imported-as-text-checkbox");const $codeImportedAsCodeCheckbox = $("#code-imported-as-code-checkbox");+const $explodeArchivesCheckbox = $("#explode-archives-checkbox");let importId;@@ -30,6 +31,7 @@ async function showDialog() {$shrinkImagesCheckbox.prop("checked", true);$textImportedAsTextCheckbox.prop("checked", true);$codeImportedAsCodeCheckbox.prop("checked", true);+ $explodeArchivesCheckbox.prop("checked", true);glob.activeDialog = $dialog;@@ -61,7 +63,8 @@ async function importIntoNote(importNoteId) {safeImport: boolToString($safeImportCheckbox),shrinkImages: boolToString($shrinkImagesCheckbox),textImportedAsText: boolToString($textImportedAsTextCheckbox),- codeImportedAsCode: boolToString($codeImportedAsCodeCheckbox)+ codeImportedAsCode: boolToString($codeImportedAsCodeCheckbox),+ explodeArchives: boolToString($explodeArchivesCheckbox)};await uploadFiles(importNoteId, files, options);@@ -76,10 +79,10 @@ async function uploadFiles(importNoteId, files, options) {const formData = new FormData();formData.append('upload', file);formData.append('importId', importId);- formData.append('safeImport', options.safeImport);- formData.append('shrinkImages', options.shrinkImages);- formData.append('textImportedAsText', options.textImportedAsText);- formData.append('codeImportedAsCode', options.codeImportedAsCode);++ for (const key in options) {+ formData.append(key, options[key]);+ }({noteId} = await $.ajax({url: baseApiUrl + 'notes/' + importNoteId + '/import',diff --git a/src/public/javascripts/services/drag_and_drop.js b/src/public/javascripts/services/drag_and_drop.jsindex 9891247c87..a05f9bbe3a 100644--- a/src/public/javascripts/services/drag_and_drop.js+++ b/src/public/javascripts/services/drag_and_drop.js@@ -42,7 +42,8 @@ const dragAndDropSetup = {safeImport: true,shrinkImages: true,textImportedAsText: true,- codeImportedAsCode: true+ codeImportedAsCode: true,+ explodeArchives: true});}else {diff --git a/src/routes/api/import.js b/src/routes/api/import.jsindex c7e4e2c3dd..12796a1abf 100644--- a/src/routes/api/import.js+++ b/src/routes/api/import.js@@ -19,7 +19,8 @@ async function importToBranch(req) {safeImport: req.body.safeImport !== 'false',shrinkImages: req.body.shrinkImages !== 'false',textImportedAsText: req.body.textImportedAsText !== 'false',- codeImportedAsCode: req.body.codeImportedAsCode !== 'false'+ codeImportedAsCode: req.body.codeImportedAsCode !== 'false',+ explodeArchives: req.body.explodeArchives !== 'false'};const file = req.file;@@ -45,11 +46,11 @@ async function importToBranch(req) {const importContext = ImportContext.getInstance(importId, options);try {- if (extension === '.tar') {+ if (extension === '.tar' && options.explodeArchives) {note = await tarImportService.importTar(importContext, file.buffer, parentNote);- } else if (extension === '.opml') {+ } else if (extension === '.opml' && options.explodeArchives) {note = await opmlImportService.importOpml(importContext, file.buffer, parentNote);- } else if (extension === '.enex') {+ } else if (extension === '.enex' && options.explodeArchives) {note = await enexImportService.importEnex(importContext, file, parentNote);} else {note = await singleImportService.importSingleFile(importContext, file, parentNote);diff --git a/src/views/dialogs/import.ejs b/src/views/dialogs/import.ejsindex ba0d7b026c..1dcb53019c 100644--- a/src/views/dialogs/import.ejs+++ b/src/views/dialogs/import.ejs@@ -31,6 +31,13 @@</label></div>+ <div class="checkbox">+ <label data-toggle="tooltip" title="If this is checked then Trilium will read <code>.tar</code>, <code>.enex</code> and <code>.opml</code> files and create notes from files insides those archives. If unchecked, then Trilium will attach the archives themselves to the note.">+ <input id="explode-archives-checkbox" value="1" type="checkbox" checked>+ Read contents of <code>.tar</code>, <code>.enex</code> and <code>.opml</code> archives.+ </label>+ </div>+<div class="checkbox"><label data-toggle="tooltip" title="<p>If you check this option, Trilium will attempt to shrink the imported images by scaling and optimization which may affect the perceived image quality. If unchecked, images will be imported without changes.</p><p>This doesn't apply to <code>.tar</code> imports with metadata since it is assumed these files are already optimized.</p>"><input id="shrink-images-checkbox" value="1" type="checkbox" checked> Shrink images