|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // 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';
-
- function wbDownloadFile(arvHost, arvToken,
- manifestReader, path) {
-
- const file = manifestReader.getFile(path);
- const name = path.split('/').reverse()[0];
- const blockRefs = file[0];
-
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/keep_services');
- prom = prom.then(xhr => {
- const services = xhr.response['items'];
- const proxies = services.filter(svc => (svc.service_type === 'proxy'));
- const n = Math.floor(Math.random() * proxies.length);
- const proxy = proxies[n];
- const blocks = [];
-
- let prom_2 = new Promise(accept => accept());
-
- for (let i = 0; i < blockRefs.length; i++) {
- const [ locator, position, size ] = blockRefs[i];
-
- const prom_1 = makeArvadosRequest(
- proxy.service_host + ':' + proxy.service_port,
- arvToken,
- '/' + locator,
- { 'useSsl': proxy.service_ssl_flag,
- 'responseType': 'arraybuffer' }
- );
-
- prom_2 = prom_2.then(() => prom_1);
-
- prom_2 = prom_2.then(xhr => (blocks.push(xhr.response.slice(position,
- position + size))));
- }
-
- prom_2 = prom_2.then(() => blocks);
-
- return prom_2;
- });
-
-
-
- /* prom = prom.then(() => {
- const blob = new Blob(blocks);
- const url = window.URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = name;
- a.click();
- }); */
-
- return prom;
- }
-
- export default wbDownloadFile;
|