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";
8 import { CollectionFile } from "../../models/collection-file";
10 export class CollectionFilesService {
12 constructor(private collectionService: CollectionService) { }
14 getFiles(collectionUuid: string) {
15 return this.collectionService
18 mapManifestToCollectionFilesTree(
19 parseKeepManifestText(
20 collection.manifestText
26 async renameFile(collectionUuid: string, file: { name: string, path: string }, newName: string) {
27 const collection = await this.collectionService.get(collectionUuid);
28 const manifest = parseKeepManifestText(collection.manifestText);
29 const updatedManifest = manifest.map(stream =>
30 stream.name === file.path
33 files: stream.files.map(f =>
35 ? { ...f, name: newName }
40 const manifestText = stringifyKeepManifest(updatedManifest);
41 return this.collectionService.update(collectionUuid, { ...collection, 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 });