Notes/src/routes/api/export.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-12-02 21:48:22 -05: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 09:07:58 -04:00
const repository = require("../../services/repository");
2017-12-02 21:48:22 -05:00
2018-03-30 15:34:07 -04:00
async function exportNote(req, res) {
2018-09-03 09:40:22 +02:00
// entityId maybe either noteId or branchId depending on format
const entityId = req.params.entityId;
2018-11-24 14:44:56 +01:00
const type = req.params.type;
const format = req.params.format;
2017-12-02 21:48:22 -05:00
2018-11-24 14:44:56 +01:00
if (type === 'tar') {
await nativeTarExportService.exportToTar(await repository.getBranch(entityId), format, res);
2018-09-03 09:40:22 +02:00
}
2018-11-24 14:44:56 +01:00
// else if (format === 'tar') {
// await markdownTarExportService.exportToMarkdown(await repository.getBranch(entityId), res);
// }
2018-09-03 09:40:22 +02: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-02 23:39:10 +02:00
}
else {
return [404, "Unrecognized export format " + format];
}
}
2018-03-30 15:34:07 -04:00
module.exports = {
exportNote
};