mirror of
https://github.com/zadam/trilium.git
synced 2025-10-31 18:36:30 +01:00
converted export/import notes
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const html = require('html');
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const tar = require('tar-stream');
|
||||
const sanitize = require("sanitize-filename");
|
||||
const Repository = require("../../services/repository");
|
||||
|
||||
router.get('/:noteId/', auth.checkApiAuthOrElectron, wrap(async (req, res, next) => {
|
||||
async function exportNote(req, res) {
|
||||
const noteId = req.params.noteId;
|
||||
const repo = new Repository(req);
|
||||
|
||||
@@ -18,7 +14,7 @@ router.get('/:noteId/', auth.checkApiAuthOrElectron, wrap(async (req, res, next)
|
||||
|
||||
const pack = tar.pack();
|
||||
|
||||
const name = await exportNote(branchId, '', pack, repo);
|
||||
const name = await exportNoteInner(branchId, '', pack, repo);
|
||||
|
||||
pack.finalize();
|
||||
|
||||
@@ -26,9 +22,9 @@ router.get('/:noteId/', auth.checkApiAuthOrElectron, wrap(async (req, res, next)
|
||||
res.setHeader('Content-Type', 'application/tar');
|
||||
|
||||
pack.pipe(res);
|
||||
}));
|
||||
}
|
||||
|
||||
async function exportNote(branchId, directory, pack, repo) {
|
||||
async function exportNoteInner(branchId, directory, pack, repo) {
|
||||
const branch = await sql.getRow("SELECT * FROM branches WHERE branchId = ?", [branchId]);
|
||||
const note = await repo.getEntity("SELECT notes.* FROM notes WHERE noteId = ?", [branch.noteId]);
|
||||
|
||||
@@ -55,7 +51,7 @@ async function exportNote(branchId, directory, pack, repo) {
|
||||
|
||||
if (children.length > 0) {
|
||||
for (const child of children) {
|
||||
await exportNote(child.branchId, childFileName + "/", pack, repo);
|
||||
await exportNoteInner(child.branchId, childFileName + "/", pack, repo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +73,6 @@ async function getMetadata(note) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
module.exports = {
|
||||
exportNote
|
||||
};
|
||||
Reference in New Issue
Block a user