2017-12-02 21:48:22 -05:00
|
|
|
"use strict";
|
|
|
|
|
2018-11-24 20:58:38 +01:00
|
|
|
const tarExportService = require('../../services/export/tar');
|
|
|
|
const singleExportService = require('../../services/export/single');
|
2018-11-16 12:12:04 +01:00
|
|
|
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-11-24 20:58:38 +01:00
|
|
|
async function exportBranch(req, res) {
|
|
|
|
const {branchId, type, format} = req.params;
|
|
|
|
const branch = await repository.getBranch(branchId);
|
2017-12-02 21:48:22 -05:00
|
|
|
|
2018-11-24 20:58:38 +01:00
|
|
|
if (type === 'subtree' && (format === 'html' || format === 'markdown')) {
|
|
|
|
await tarExportService.exportToTar(branch, format, res);
|
2018-09-03 09:40:22 +02:00
|
|
|
}
|
2018-11-24 20:58:38 +01:00
|
|
|
else if (type === 'single') {
|
|
|
|
await singleExportService.exportSingleNote(branch, format, res);
|
2018-11-16 12:12:04 +01:00
|
|
|
}
|
|
|
|
else if (format === 'opml') {
|
2018-11-24 20:58:38 +01:00
|
|
|
await opmlExportService.exportToOpml(branch, res);
|
2018-09-02 23:39:10 +02:00
|
|
|
}
|
2018-05-27 12:26:34 -04:00
|
|
|
else {
|
|
|
|
return [404, "Unrecognized export format " + format];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 15:34:07 -04:00
|
|
|
module.exports = {
|
2018-11-24 20:58:38 +01:00
|
|
|
exportBranch
|
2018-03-30 15:34:07 -04:00
|
|
|
};
|