IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import makeArvadosRequest from 'make-arvados-request';
  8. class WBArvadosCollection {
  9. constructor(arvHost, arvToken, uuid) {
  10. this.arvHost = arvHost;
  11. this.arvToken = arvToken;
  12. this.uuid = uuid;
  13. this.meta = null;
  14. }
  15. fetchMeta() {
  16. let prom = makeArvadosRequest(this.arvHost, this.arvToken,
  17. '/arvados/v1/collections/' + this.uuid);
  18. prom = prom.then(xhr => {
  19. this.meta = xhr.response;
  20. });
  21. return prom;
  22. }
  23. parseManifest() {
  24. if (this.meta === null)
  25. throw Error('You must call fetchMeta() first and wait for the returned Promise.');
  26. let manifest = this.meta.manifest_text;
  27. let streams = manifest.split('\n');
  28. this.content = streams.map(s => {
  29. let tokens = s.split(' ');
  30. let streamName = tokens[0];
  31. let rx = /^[a-f0-9]{32}\+[0-9]+/;
  32. let n = tokens.map(t => rx.exec(t));
  33. n = n.indexOf(null);
  34. let locators = tokens.slice(1, n)
  35. let fileTokens = tokens.slice(n);
  36. let fileNames = fileTokens.map(t => t.split(':')[2]);
  37. let fileSizes = {};
  38. fileTokens.map(t => {
  39. let [ start, end, name ] = t.split(':');
  40. if (!(name in fileSizes))
  41. fileSizes[name] = 0;
  42. fileSizes[name] += Number(end) - Number(start);
  43. });
  44. fileSizes = fileNames.map(n => fileSizes[n]);
  45. return [ streamName, fileNames, fileSizes ];
  46. });
  47. return this.content;
  48. }
  49. }
  50. export WBArvadosCollection;