//
// 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<CollectionDirectory | CollectionFile>) => {
return mapTree<CollectionDirectory | CollectionFile>(node => {
const children = getNodeChildren(node.id)(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
.replace(collectionUrlPrefix, '')
.replace(nameSuffix, '');
-
+ const parentPath = directory.replace(/\/$/, '');
const data = {
url,
id: [
collectionUuid ? collectionUuid : '',
- directory ? '/' + directory : '',
+ directory ? parentPath : '',
'/' + name
].join(''),
name,
- path: directory,
+ path: parentPath,
};
return getTagValue(element, 'D:resourcetype', '')