trilium/src/public/javascripts/services/export.js

40 lines
1 KiB
JavaScript
Raw Normal View History

import treeService from './tree.js';
import protectedSessionHolder from './protected_session_holder.js';
import utils from './utils.js';
2018-03-31 03:34:07 +08:00
import server from './server.js';
2018-02-25 23:55:21 +08:00
function exportBranch(noteId, format) {
const url = utils.getHost() + "/api/notes/" + noteId + "/export/" + format +
"?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
2018-02-25 23:55:21 +08:00
utils.download(url);
}
let importNoteId;
2018-04-02 08:33:10 +08:00
function importBranch(noteId) {
importNoteId = noteId;
$("#import-upload").trigger('click');
}
$("#import-upload").change(async function() {
const formData = new FormData();
formData.append('upload', this.files[0]);
await $.ajax({
2018-04-02 08:33:10 +08:00
url: baseApiUrl + 'notes/' + importNoteId + '/import',
headers: server.getHeaders(),
data: formData,
type: 'POST',
contentType: false, // NEEDED, DON'T OMIT THIS
processData: false, // NEEDED, DON'T OMIT THIS
});
2018-02-25 23:55:21 +08:00
await treeService.reload();
});
export default {
2018-04-02 08:33:10 +08:00
exportBranch,
importBranch
};