2017-12-03 10:48:22 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-11-16 19:12:04 +08:00
|
|
|
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;
|
2018-05-28 00:26:34 +08:00
|
|
|
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') {
|
2018-11-16 19:12:04 +08:00
|
|
|
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
|
|
|
}
|
2018-05-28 00:26:34 +08:00
|
|
|
else {
|
|
|
|
return [404, "Unrecognized export format " + format];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 03:34:07 +08:00
|
|
|
module.exports = {
|
|
|
|
exportNote
|
|
|
|
};
|