trilium/src/routes/api/export.js

28 lines
898 B
JavaScript
Raw Normal View History

2017-12-03 10:48:22 +08:00
"use strict";
2018-11-25 03:58:38 +08:00
const tarExportService = require('../../services/export/tar');
const singleExportService = require('../../services/export/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-11-25 03:58:38 +08:00
async function exportBranch(req, res) {
const {branchId, type, format} = req.params;
const branch = await repository.getBranch(branchId);
2017-12-03 10:48:22 +08:00
2018-11-25 03:58:38 +08:00
if (type === 'subtree' && (format === 'html' || format === 'markdown')) {
await tarExportService.exportToTar(branch, format, res);
2018-09-03 15:40:22 +08:00
}
2018-11-25 03:58:38 +08:00
else if (type === 'single') {
await singleExportService.exportSingleNote(branch, format, res);
}
else if (format === 'opml') {
2018-11-25 03:58:38 +08:00
await opmlExportService.exportToOpml(branch, 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 = {
2018-11-25 03:58:38 +08:00
exportBranch
2018-03-31 03:34:07 +08:00
};