Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / services / collection-service / collection-service-files-response.ts
index 9583b7a4ebd749ffaa2898ad176830c4214f8573..db56e317ff2474932c4d55702884d2f963e91860 100644 (file)
@@ -3,9 +3,8 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file";
-import { getTagValue } from "~/common/xml";
-import { getNodeChildren, Tree, mapTree } from '~/models/tree';
-import { customDecodeURI } from "~/common/url";
+import { getTagValue } from "common/xml";
+import { getNodeChildren, Tree, mapTree } from 'models/tree';
 
 export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>) => {
     return mapTree<CollectionDirectory | CollectionFile>(node => {
@@ -21,21 +20,22 @@ export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>)
 };
 
 export const extractFilesData = (document: Document) => {
-    const collectionUrlPrefix = /\/c=([^\/]*)/;
+    const collectionUrlPrefix = /\/c=([^/]*)/;
     return Array
         .from(document.getElementsByTagName('D:response'))
         .slice(1) // omit first element which is collection itself
         .map(element => {
-            const name = getTagValue(element, 'D:displayname', '');
-            const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
-            const href = getTagValue(element, 'D:href', '');
-            const url = customDecodeURI(href);
-            const nameSuffix = name;
+            const name = getTagValue(element, 'D:displayname', '', true); // skip decoding as value should be already decoded
+            const size = parseInt(getTagValue(element, 'D:getcontentlength', '0', true), 10);
+            const url = getTagValue(element, 'D:href', '', true);
             const collectionUuidMatch = collectionUrlPrefix.exec(url);
             const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';
-            const directory = url
+            const pathArray = url.split(`/`);
+            if (!pathArray.pop()) {
+                pathArray.pop();
+            }
+            const directory = pathArray.join('/')
                 .replace(collectionUrlPrefix, '')
-                .replace(nameSuffix, '')
                 .replace(/\/\//g, '/');
 
             const parentPath = directory.replace(/\/$/, '');
@@ -43,11 +43,11 @@ export const extractFilesData = (document: Document) => {
                 url,
                 id: [
                     collectionUuid ? collectionUuid : '',
-                    directory ? parentPath : '',
+                    directory ? unescape(parentPath) : '',
                     '/' + name
                 ].join(''),
                 name,
-                path: parentPath,
+                path: unescape(parentPath),
             };
 
             const result = getTagValue(element, 'D:resourcetype', '')
@@ -60,4 +60,4 @@ export const extractFilesData = (document: Document) => {
 
 export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) => {
     return `${path}/${name}`;
-};
\ No newline at end of file
+};