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!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

wb-download-file.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. function wbDownloadFile(arvHost, arvToken,
  9. manifestReader, path) {
  10. const file = manifestReader.getFile(path);
  11. const name = path.split('/').reverse()[0];
  12. const blockRefs = file[0];
  13. let prom = makeArvadosRequest(arvHost, arvToken,
  14. '/arvados/v1/keep_services');
  15. prom = prom.then(xhr => {
  16. const services = xhr.response['items'];
  17. const proxies = services.filter(svc => (svc.service_type === 'proxy'));
  18. const n = Math.floor(Math.random() * proxies.length);
  19. const proxy = proxies[n];
  20. const blocks = [];
  21. let prom_2 = new Promise(accept => accept());
  22. for (let i = 0; i < blockRefs.length; i++) {
  23. const [ locator, position, size ] = blockRefs[i];
  24. const prom_1 = makeArvadosRequest(
  25. proxy.service_host + ':' + proxy.service_port,
  26. arvToken,
  27. '/' + locator,
  28. { 'useSsl': proxy.service_ssl_flag,
  29. 'responseType': 'arraybuffer' }
  30. );
  31. prom_2 = prom_2.then(() => prom_1);
  32. prom_2 = prom_2.then(xhr => (blocks.push(xhr.response.slice(position,
  33. position + size))));
  34. }
  35. prom_2 = prom_2.then(() => blocks);
  36. return prom_2;
  37. });
  38. /* prom = prom.then(() => {
  39. const blob = new Blob(blocks);
  40. const url = window.URL.createObjectURL(blob);
  41. const a = document.createElement('a');
  42. a.href = url;
  43. a.download = name;
  44. a.click();
  45. }); */
  46. return prom;
  47. }
  48. export default wbDownloadFile;