From caf4e9f28c0c8c8d4eea3c5b230c74bf5c3a98a4 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 5 Nov 2021 17:15:52 -0400 Subject: [PATCH] ImportHandler: Use truthiness to signal conversion handled --- doc/api/hooks_server-side.md | 4 ++-- src/node/handler/ImportHandler.js | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index c63a81a08..23428eb4e 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -812,8 +812,8 @@ exports.exportEtherpadAdditionalContent = () => ['comments']; Called from: `src/node/handler/ImportHandler.js` Called when a user submits a document for import, before the document is -converted to HTML. The hook function should return `undefined` (or an empty -list) if it did NOT convert convert the document to HTML. +converted to HTML. The hook function should return a truthy value if the hook +function elected to convert the document to HTML. Context properties: diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 7cc62e113..7e3313524 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -142,11 +142,8 @@ const doImport = async (req, res, padId) => { } const destFile = path.join(tmpDirectory, `etherpad_import_${randNum}.${exportExtension}`); - - // Logic for allowing external Import Plugins - const result = await hooks.aCallAll('import', {srcFile, destFile, fileEnding}); - const importHandledByPlugin = (result.length > 0); // This feels hacky and wrong.. - + const importHandledByPlugin = + (await hooks.aCallAll('import', {srcFile, destFile, fileEnding})).some((x) => x); const fileIsEtherpad = (fileEnding === '.etherpad'); const fileIsHTML = (fileEnding === '.html' || fileEnding === '.htm'); const fileIsTXT = (fileEnding === '.txt');