Skip to content

Commit

Permalink
nodejs: getting name in wopi (Fix Bug 70092)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Sep 18, 2024
1 parent b9b4aef commit 4c8fb6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 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 @@ -61,7 +61,8 @@ documentService.getConvertedUri = function getConvertedUri(
filePass = null,
lang = null,
) {
const fromExt = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension
// get the current document extension
const fromExt = fromExtension || fileUtility.getFileExtension(documentUri, false, true);

// get the current document name or uuid
const title = fileUtility.getFileNameFromUrl(documentUri) || guidManager.newGuid();
Expand Down
15 changes: 8 additions & 7 deletions web/documentserver-example/nodejs/helpers/fileUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ fileUtility.getFileName = function getFileName(path, withoutExtension) {
return fileName;
};

// get file extension from the given url
fileUtility.getFileExtension = function getFileExtension(url, withoutDot) {
if (!url) return null;
// get file extension from the given path
fileUtility.getFileExtension = function getFileExtension(path, withoutDot, isUrl) {
if (!path) return null;

const fileName = fileUtility.getFileNameFromUrl(url); // get file name from the given url
// get file name from the given path
const fileName = isUrl ? fileUtility.getFileNameFromUrl(path) : fileUtility.getFileName(path);

const parts = fileName.toLowerCase().split('.');

return withoutDot ? parts.pop() : `.${parts.pop()}`; // get the extension from the file name with or without dot
};

// get file type from the given url
fileUtility.getFileType = function getFileType(url) {
const ext = fileUtility.getFileExtension(url, true); // get the file extension from the given url
// get file type from the given path
fileUtility.getFileType = function getFileType(path) {
const ext = fileUtility.getFileExtension(path, true); // get the file extension from the given path

for (let i = 0; i < supportedFormats.length; i++) {
if (supportedFormats[i].name === ext && supportedFormats[i].type !== '') return supportedFormats[i].type;
Expand Down

0 comments on commit 4c8fb6b

Please sign in to comment.