X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c0e5f8f04311c22ca8e0be32c1c1da88ae1cceec..15073a5905fee439e6b3908d1e805050ff10936b:/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 b8a7970d..325339d0 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -2,16 +2,10 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { createCollectionFilesTree, CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file"; +import { CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file"; import { getTagValue } from "~/common/xml"; import { getNodeChildren, Tree, mapTree } from '~/models/tree'; -export const parseFilesResponse = (document: Document) => { - const files = extractFilesData(document); - const tree = createCollectionFilesTree(files); - return sortFilesTree(tree); -}; - export const sortFilesTree = (tree: Tree) => { return mapTree(node => { const children = getNodeChildren(node.id)(tree); @@ -26,29 +20,44 @@ export const sortFilesTree = (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 .map(element => { - const name = getTagValue(element, 'D:displayname', ''); - const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10); - const url = getTagValue(element, 'D:href', ''); - const nameSuffix = `/${name || ''}`; - const directory = url + 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 pathArray = url.split(`/`); + if (!pathArray.pop()) { + pathArray.pop(); + } + const directory = pathArray.join('/') .replace(collectionUrlPrefix, '') - .replace(nameSuffix, ''); + .replace(/\/\//g, '/'); + const parentPath = directory.replace(/\/$/, ''); const data = { url, - id: `${directory}/${name}`, + id: [ + collectionUuid ? collectionUuid : '', + directory ? unescape(parentPath) : '', + '/' + name + ].join(''), name, - path: directory, + path: unescape(parentPath), }; - return getTagValue(element, 'D:resourcetype', '') + const result = getTagValue(element, 'D:resourcetype', '') ? createCollectionDirectory(data) : createCollectionFile({ ...data, size }); + return result; }); }; + +export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) => { + return `${path}/${name}`; +}; \ No newline at end of file