From 8cf285c51b46403c6f123d09537786b185290dac Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 10 Sep 2024 22:35:50 +0300 Subject: [PATCH] nodejs: separate method for getting fileName from url (Fix Bug 70092) --- .../nodejs/helpers/documentService.js | 3 ++- .../nodejs/helpers/fileUtility.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/web/documentserver-example/nodejs/helpers/documentService.js b/web/documentserver-example/nodejs/helpers/documentService.js index ec3b86751..08419cc77 100755 --- a/web/documentserver-example/nodejs/helpers/documentService.js +++ b/web/documentserver-example/nodejs/helpers/documentService.js @@ -63,7 +63,8 @@ documentService.getConvertedUri = function getConvertedUri( ) { const fromExt = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension - const title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid + // get the current document name or uuid + const title = fileUtility.getFileNameFromUrl(documentUri) || guidManager.newGuid(); // generate the document key value const revisionId = documentService.generateRevisionId(documentRevisionId || documentUri); diff --git a/web/documentserver-example/nodejs/helpers/fileUtility.js b/web/documentserver-example/nodejs/helpers/fileUtility.js index e0b67f2e4..25fca0bdd 100644 --- a/web/documentserver-example/nodejs/helpers/fileUtility.js +++ b/web/documentserver-example/nodejs/helpers/fileUtility.js @@ -25,14 +25,22 @@ fileUtility.getFormats = function getFormats() { }; // get file name from the given url -fileUtility.getFileName = function getFileName(url, withoutExtension) { +fileUtility.getFileNameFromUrl = function getFileNameFromUrl(url, withoutExtension) { if (!url) return ''; let parts = url.split('\\'); parts = parts.pop(); - parts = parts.split('/'); - let fileName = parts.pop(); // get the file name from the last part of the url - [fileName] = fileName.split('?'); + const path = parts.split('?')[0]; + + return fileUtility.getFileName(path, withoutExtension); +}; + +// get file name +fileUtility.getFileName = function getFileName(path, withoutExtension) { + if (!path) return ''; + + const parts = path.split('/'); + const fileName = parts.pop(); // get the file name from the last part of the path // get file name without extension if (withoutExtension) { @@ -46,7 +54,7 @@ fileUtility.getFileName = function getFileName(url, withoutExtension) { fileUtility.getFileExtension = function getFileExtension(url, withoutDot) { if (!url) return null; - const fileName = fileUtility.getFileName(url); // get file name from the given url + const fileName = fileUtility.getFileNameFromUrl(url); // get file name from the given url const parts = fileName.toLowerCase().split('.');