// // Copyright (C) Stanislaw Adaszewski, 2020 // Contact: s.adaszewski@gmail.com // Website: https://adared.ch/wba // License: GNU Affero General Public License, Version 3 // import makeArvadosRequest from 'make-arvados-request'; class WBArvadosCollection { constructor(arvHost, arvToken, uuid) { this.arvHost = arvHost; this.arvToken = arvToken; this.uuid = uuid; this.meta = null; } fetchMeta() { let prom = makeArvadosRequest(this.arvHost, this.arvToken, '/arvados/v1/collections/' + this.uuid); prom = prom.then(xhr => { this.meta = xhr.response; }); return prom; } parseManifest() { if (this.meta === null) throw Error('You must call fetchMeta() first and wait for the returned Promise.'); let manifest = this.meta.manifest_text; let streams = manifest.split('\n'); this.content = streams.map(s => { let tokens = s.split(' '); let streamName = tokens[0]; let rx = /^[a-f0-9]{32}\+[0-9]+/; let n = tokens.map(t => rx.exec(t)); n = n.indexOf(null); let locators = tokens.slice(1, n) let fileTokens = tokens.slice(n); let fileNames = fileTokens.map(t => t.split(':')[2]); let fileSizes = {}; fileTokens.map(t => { let [ start, end, name ] = t.split(':'); if (!(name in fileSizes)) fileSizes[name] = 0; fileSizes[name] += Number(end) - Number(start); }); fileSizes = fileNames.map(n => fileSizes[n]); return [ streamName, fileNames, fileSizes ]; }); return this.content; } } export WBArvadosCollection;