1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { CollectionService } from "../collection-service/collection-service";
6 import { parseKeepManifestText, stringifyKeepManifest } from "./collection-manifest-parser";
7 import { mapManifestToCollectionFilesTree } from "./collection-manifest-mapper";
9 export class CollectionFilesService {
11 constructor(private collectionService: CollectionService) { }
13 getFiles(collectionUuid: string) {
14 return this.collectionService
17 mapManifestToCollectionFilesTree(
18 parseKeepManifestText(
19 collection.manifestText
25 async renameFile(collectionUuid: string, file: { name: string, path: string }, newName: string) {
26 const collection = await this.collectionService.get(collectionUuid);
27 const manifest = parseKeepManifestText(collection.manifestText);
28 const updatedManifest = manifest.map(
29 stream => stream.name === file.path
32 files: stream.files.map(
33 f => f.name === file.name
34 ? { ...f, name: newName }
40 const manifestText = stringifyKeepManifest(updatedManifest);
41 return this.collectionService.update(collectionUuid, { manifestText });
44 async deleteFile(collectionUuid: string, file: { name: string, path: string }) {
45 const collection = await this.collectionService.get(collectionUuid);
46 const manifest = parseKeepManifestText(collection.manifestText);
47 const updatedManifest = manifest.map(stream =>
48 stream.name === file.path
51 files: stream.files.filter(f => f.name !== file.name)
55 const manifestText = stringifyKeepManifest(updatedManifest);
56 return this.collectionService.update(collectionUuid, { manifestText });