added "explodeArchives" option to the import dialog

This commit is contained in:
zadam 2019-02-25 22:38:48 +01:00
parent 7e2a2baa5d
commit 8b3e721028
4 changed files with 22 additions and 10 deletions

View File

@ -16,6 +16,7 @@ const $safeImportCheckbox = $("#safe-import-checkbox");
const $shrinkImagesCheckbox = $("#shrink-images-checkbox"); const $shrinkImagesCheckbox = $("#shrink-images-checkbox");
const $textImportedAsTextCheckbox = $("#text-imported-as-text-checkbox"); const $textImportedAsTextCheckbox = $("#text-imported-as-text-checkbox");
const $codeImportedAsCodeCheckbox = $("#code-imported-as-code-checkbox"); const $codeImportedAsCodeCheckbox = $("#code-imported-as-code-checkbox");
const $explodeArchivesCheckbox = $("#explode-archives-checkbox");
let importId; let importId;
@ -30,6 +31,7 @@ async function showDialog() {
$shrinkImagesCheckbox.prop("checked", true); $shrinkImagesCheckbox.prop("checked", true);
$textImportedAsTextCheckbox.prop("checked", true); $textImportedAsTextCheckbox.prop("checked", true);
$codeImportedAsCodeCheckbox.prop("checked", true); $codeImportedAsCodeCheckbox.prop("checked", true);
$explodeArchivesCheckbox.prop("checked", true);
glob.activeDialog = $dialog; glob.activeDialog = $dialog;
@ -61,7 +63,8 @@ async function importIntoNote(importNoteId) {
safeImport: boolToString($safeImportCheckbox), safeImport: boolToString($safeImportCheckbox),
shrinkImages: boolToString($shrinkImagesCheckbox), shrinkImages: boolToString($shrinkImagesCheckbox),
textImportedAsText: boolToString($textImportedAsTextCheckbox), textImportedAsText: boolToString($textImportedAsTextCheckbox),
codeImportedAsCode: boolToString($codeImportedAsCodeCheckbox) codeImportedAsCode: boolToString($codeImportedAsCodeCheckbox),
explodeArchives: boolToString($explodeArchivesCheckbox)
}; };
await uploadFiles(importNoteId, files, options); await uploadFiles(importNoteId, files, options);
@ -76,10 +79,10 @@ async function uploadFiles(importNoteId, files, options) {
const formData = new FormData(); const formData = new FormData();
formData.append('upload', file); formData.append('upload', file);
formData.append('importId', importId); formData.append('importId', importId);
formData.append('safeImport', options.safeImport);
formData.append('shrinkImages', options.shrinkImages); for (const key in options) {
formData.append('textImportedAsText', options.textImportedAsText); formData.append(key, options[key]);
formData.append('codeImportedAsCode', options.codeImportedAsCode); }
({noteId} = await $.ajax({ ({noteId} = await $.ajax({
url: baseApiUrl + 'notes/' + importNoteId + '/import', url: baseApiUrl + 'notes/' + importNoteId + '/import',

View File

@ -42,7 +42,8 @@ const dragAndDropSetup = {
safeImport: true, safeImport: true,
shrinkImages: true, shrinkImages: true,
textImportedAsText: true, textImportedAsText: true,
codeImportedAsCode: true codeImportedAsCode: true,
explodeArchives: true
}); });
} }
else { else {

View File

@ -19,7 +19,8 @@ async function importToBranch(req) {
safeImport: req.body.safeImport !== 'false', safeImport: req.body.safeImport !== 'false',
shrinkImages: req.body.shrinkImages !== 'false', shrinkImages: req.body.shrinkImages !== 'false',
textImportedAsText: req.body.textImportedAsText !== '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; const file = req.file;
@ -45,11 +46,11 @@ async function importToBranch(req) {
const importContext = ImportContext.getInstance(importId, options); const importContext = ImportContext.getInstance(importId, options);
try { try {
if (extension === '.tar') { if (extension === '.tar' && options.explodeArchives) {
note = await tarImportService.importTar(importContext, file.buffer, parentNote); 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); 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); note = await enexImportService.importEnex(importContext, file, parentNote);
} else { } else {
note = await singleImportService.importSingleFile(importContext, file, parentNote); note = await singleImportService.importSingleFile(importContext, file, parentNote);

View File

@ -31,6 +31,13 @@
</label> </label>
</div> </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"> <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>"> <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 <input id="shrink-images-checkbox" value="1" type="checkbox" checked> Shrink images