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!
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

wb-download-file.js 1.5KB

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