Skip to content

Commit

Permalink
nodejs: separate method for getting fileName from url (Fix Bug 70092)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Sep 10, 2024
1 parent 4ae4687 commit 8cf285c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion web/documentserver-example/nodejs/helpers/documentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions web/documentserver-example/nodejs/helpers/fileUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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('.');

Expand Down

0 comments on commit 8cf285c

Please sign in to comment.