trilium/src/routes/api/export.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-12-03 10:48:22 +08:00
"use strict";
const nativeTarExportService = require('../../services/export/native_tar');
const markdownTarExportService = require('../../services/export/markdown_tar');
const markdownSingleExportService = require('../../services/export/markdown_single');
const opmlExportService = require('../../services/export/opml');
2018-03-31 21:07:58 +08:00
const repository = require("../../services/repository");
2017-12-03 10:48:22 +08:00
2018-03-31 03:34:07 +08:00
async function exportNote(req, res) {
2018-09-03 15:40:22 +08:00
// entityId maybe either noteId or branchId depending on format
const entityId = req.params.entityId;
2018-11-24 21:44:56 +08:00
const type = req.params.type;
const format = req.params.format;
2017-12-03 10:48:22 +08:00
2018-11-24 21:44:56 +08:00
if (type === 'tar') {
await nativeTarExportService.exportToTar(await repository.getBranch(entityId), format, res);
2018-09-03 15:40:22 +08:00
}
2018-11-24 21:44:56 +08:00
// else if (format === 'tar') {
// await markdownTarExportService.exportToMarkdown(await repository.getBranch(entityId), res);
// }
2018-09-03 15:40:22 +08:00
// export single note without subtree
else if (format === 'markdown-single') {
await markdownSingleExportService.exportSingleMarkdown(await repository.getNote(entityId), res);
}
else if (format === 'opml') {
await opmlExportService.exportToOpml(await repository.getBranch(entityId), res);
2018-09-03 05:39:10 +08:00
}
else {
return [404, "Unrecognized export format " + format];
}
}
2018-03-31 03:34:07 +08:00
module.exports = {
exportNote
};