X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/57cdabb27166c3921f8775fff8f488c7f299aafc..4e862392eae3d1a1846b3f33c6e29f4e68c31aca:/src/services/collection-service/collection-service.ts diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index 3280d05e82..b6272650de 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -2,14 +2,17 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { CollectionResource } from "~/models/collection"; +import { CollectionResource } from "models/collection"; import { AxiosInstance } from "axios"; -import { CollectionFile, CollectionDirectory } from "~/models/collection-file"; -import { WebDAV } from "~/common/webdav"; +import { CollectionFile, CollectionDirectory } from "models/collection-file"; +import { WebDAV } from "common/webdav"; import { AuthService } from "../auth-service/auth-service"; import { extractFilesData } from "./collection-service-files-response"; -import { TrashableResourceService } from "~/services/common-service/trashable-resource-service"; -import { ApiActions } from "~/services/api/api-actions"; +import { TrashableResourceService } from "services/common-service/trashable-resource-service"; +import { ApiActions } from "services/api/api-actions"; +import { customEncodeURI } from "common/url"; +import { FilterBuilder } from "services/api/filter-builder"; +import { ListArguments } from "services/common-service/common-service"; export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void; @@ -27,16 +30,25 @@ export class CollectionService extends TrashableResourceService) { return super.create({ ...data, preserveVersion: true }); } - async update(uuid: string, data: Partial) { - // First make the changes - const collection = await super.update(uuid, data); - if (data === { preserveVersion: true }) { return collection; } - // Then set the head version to be preserved - return await super.update(uuid, { preserveVersion: true }); + update(uuid: string, data: Partial) { + const select = [...Object.keys(data), 'version', 'modifiedAt']; + return super.update(uuid, { ...data, preserveVersion: true }, select); } async files(uuid: string) { @@ -48,13 +60,23 @@ export class CollectionService extends TrashableResourceService a.length - b.length) + .reduce((acc, currentPath) => { + const parentPathFound = acc.find((parentPath) => currentPath.indexOf(`${parentPath}/`) > -1); + + if (!parentPathFound) { + return [...acc, currentPath]; + } + + return acc; + }, []); + + for (const path of sortedUniquePaths) { + if (path.indexOf(collectionUuid) === -1) { await this.webdavClient.delete(`c=${collectionUuid}${path}`); + } else { + await this.webdavClient.delete(`c=${path}`); } } await this.update(collectionUuid, { preserveVersion: true }); @@ -72,9 +94,9 @@ export class CollectionService extends TrashableResourceService { @@ -100,7 +122,7 @@ export class CollectionService extends TrashableResourceService { onProgress(fileId, e.loaded, e.total, Date.now()); - } + }, }; return this.webdavClient.upload(fileURL, [file], requestConfig); }