X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/25aa8a7c81609525d300f38bc5b7d2344c4e1cdf..77f285190a3ae77a1075b249ca964b1afeed7ca2:/src/services/collection-service/collection-service-files-response.ts diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts index 581a6fa661..619a4fc785 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -3,8 +3,8 @@ // SPDX-License-Identifier: AGPL-3.0 import { createCollectionFilesTree, CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file"; -import { Tree, mapTree, getNodeChildren, getNode, TreeNode } from "../../models/tree"; -import { getTagValue } from "../../common/xml"; +import { getTagValue } from "~/common/xml"; +import { getNodeChildren, Tree, mapTree } from '~/models/tree'; export const parseFilesResponse = (document: Document) => { const files = extractFilesData(document); @@ -13,10 +13,8 @@ export const parseFilesResponse = (document: Document) => { }; export const sortFilesTree = (tree: Tree) => { - return mapTree(node => { - const children = getNodeChildren(node.id)(tree) - .map(id => getNode(id)(tree)) - .filter(node => node !== undefined) as TreeNode[]; + return mapTree(node => { + const children = getNodeChildren(node.id)(tree); children.sort((a, b) => a.value.type !== b.value.type @@ -24,11 +22,11 @@ export const sortFilesTree = (tree: Tree) : a.value.name.localeCompare(b.value.name) ); return { ...node, children: children.map(child => child.id) }; - })(tree) as Tree; + })(tree); }; export const extractFilesData = (document: Document) => { - const collectionUrlPrefix = /\/c=[0-9a-zA-Z\-]*/; + const collectionUrlPrefix = /\/c=([^\/]*)/; return Array .from(document.getElementsByTagName('D:response')) .slice(1) // omit first element which is collection itself @@ -37,13 +35,20 @@ export const extractFilesData = (document: Document) => { const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10); const url = getTagValue(element, 'D:href', ''); const nameSuffix = `/${name || ''}`; + const collectionUuidMatch = collectionUrlPrefix.exec(url); + const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : ''; const directory = url .replace(collectionUrlPrefix, '') .replace(nameSuffix, ''); + const data = { url, - id: `${directory}/${name}`, + id: [ + collectionUuid ? collectionUuid : '', + directory ? '/' + directory.replace(/^\//, '') : '', + '/' + name + ].join(''), name, path: directory, }; @@ -54,3 +59,6 @@ export const extractFilesData = (document: Document) => { }); }; + +export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) => + `${path}/${name}`;