From a7fce3375010d5b70a0c08bd5a4b64e3199c5962 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 16 Feb 2019 23:58:42 +0100 Subject: [PATCH] OPML v2 export --- src/public/javascripts/dialogs/export.js | 2 ++ src/routes/api/export.js | 2 +- src/routes/api/import.js | 2 +- src/services/export/opml.js | 24 ++++++++++++++++++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/public/javascripts/dialogs/export.js b/src/public/javascripts/dialogs/export.js index a2d5faa8b..9c8bdc8fc 100644 --- a/src/public/javascripts/dialogs/export.js +++ b/src/public/javascripts/dialogs/export.js @@ -39,6 +39,8 @@ async function showDialog(defaultType) { throw new Error("Unrecognized type " + defaultType); } + $("#opml-v2").prop("checked", true); // setting default + glob.activeDialog = $dialog; $dialog.modal(); diff --git a/src/routes/api/export.js b/src/routes/api/export.js index f042be2d7..59d6a20d3 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -38,7 +38,7 @@ class ExportContext { }); } - // must remaing static + // must remaing non-static async reportError(message) { await messagingService.sendMessageToAllClients({ type: 'export-error', diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 59161e3c2..ee048759a 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -46,7 +46,7 @@ class ImportContext { }); } - // must remaing static + // must remaing non-static async reportError(message) { await messagingService.sendMessageToAllClients({ type: 'import-error', diff --git a/src/services/export/opml.js b/src/services/export/opml.js index 5d8c7604b..03f14baec 100644 --- a/src/services/export/opml.js +++ b/src/services/export/opml.js @@ -4,7 +4,11 @@ const repository = require("../repository"); const utils = require('../utils'); async function exportToOpml(exportContext, branch, version, res) { - console.log("EXPORTING VERSION ", version); + if (!['1.0', '2.0'].includes(version)) { + throw new Error("Unrecognized OPML version " + version); + } + + const opmlVersion = parseInt(version); const note = await branch.getNote(); @@ -18,10 +22,21 @@ async function exportToOpml(exportContext, branch, version, res) { const title = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title; - const preparedTitle = prepareText(title); - const preparedContent = prepareText(await note.getContent()); + if (opmlVersion === 1) { + const preparedTitle = escapeXmlAttribute(title); + const preparedContent = prepareText(await note.getContent()); - res.write(`\n`); + res.write(`\n`); + } + else if (opmlVersion === 2) { + const preparedTitle = escapeXmlAttribute(title); + const preparedContent = escapeXmlAttribute(await note.getContent()); + + res.write(`\n`); + } + else { + throw new Error("Unrecognized OPML version " + opmlVersion); + } exportContext.increaseProgressCount(); @@ -32,6 +47,7 @@ async function exportToOpml(exportContext, branch, version, res) { res.write(''); } + const filename = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title + ".opml"; res.setHeader('Content-Disposition', utils.getContentDisposition(filename));