mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import treeService from './tree.js';
|
|
import infoService from './info.js';
|
|
import protectedSessionHolder from './protected_session_holder.js';
|
|
import utils from './utils.js';
|
|
import server from './server.js';
|
|
|
|
function exportSubtree(noteId, format) {
|
|
const url = utils.getHost() + "/api/notes/" + noteId + "/export/" + format +
|
|
"?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
|
|
|
utils.download(url);
|
|
|
|
infoService.showMessage("Export to file has been finished.");
|
|
}
|
|
|
|
let importNoteId;
|
|
|
|
function importIntoNote(noteId) {
|
|
importNoteId = noteId;
|
|
|
|
$("#import-upload").trigger('click');
|
|
}
|
|
|
|
$("#import-upload").change(async function() {
|
|
const formData = new FormData();
|
|
formData.append('upload', this.files[0]);
|
|
|
|
await $.ajax({
|
|
url: baseApiUrl + 'notes/' + importNoteId + '/import',
|
|
headers: server.getHeaders(),
|
|
data: formData,
|
|
dataType: 'json',
|
|
type: 'POST',
|
|
contentType: false, // NEEDED, DON'T REMOVE THIS
|
|
processData: false, // NEEDED, DON'T REMOVE THIS
|
|
})
|
|
.fail((xhr, status, error) => alert('Import error: ' + xhr.responseText))
|
|
.done(async note => {
|
|
await treeService.reload();
|
|
|
|
if (note) {
|
|
const node = await treeService.activateNote(note.noteId);
|
|
|
|
node.setExpanded(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
export default {
|
|
exportSubtree,
|
|
importIntoNote
|
|
}; |