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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

wb-image-viewer-page.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { h, Component } from 'preact';
  2. import makeArvadosRequest from 'make-arvados-request';
  3. function downloadFile(arvHost, arvToken, file) {
  4. const blockRefs = file[0];
  5. let prom = makeArvadosRequest(arvHost, arvToken,
  6. '/arvados/v1/keep_services');
  7. let proxy;
  8. prom = prom.then(xhr => {
  9. const services = xhr.response['items'];
  10. const proxies = services.filter(svc => (svc.service_type === 'proxy'));
  11. const n = Math.floor(Math.random() * proxies.length);
  12. proxy = proxies[n];
  13. });
  14. const blocks = [];
  15. for (let i = 0; i < blockRefs.length; i++) {
  16. let locator, start, end;
  17. prom = prom.then(() => {
  18. [ locator, start, end ] = blockRefs[i];
  19. return makeArvadosRequest(
  20. proxy.service_host + ':' + proxy.service_port,
  21. arvToken, '/' + locator,
  22. { 'useSsl': proxy.service_ssl_flag,
  23. 'responseType': 'arraybuffer' }
  24. );
  25. });
  26. prom = prom.then(xhr => blocks.push(xhr.response.slice(start, end)));
  27. }
  28. prom = prom.then(() => {
  29. const url = URL.createObjectURL(new Blob(blocks));
  30. const totalSize = blocks.reduce((a, b) => a.length + b.length);
  31. const big = new Uint8Array(totalSize);
  32. for (let i = 0, pos = 0; i < blocks.length; i++) {
  33. big.set(blocks[i], pos);
  34. pos += blocks[i].length;
  35. }
  36. // papayaContainers[0].startPapaya();
  37. const poll = () => {
  38. setTimeout(() => {
  39. console.log('Polling Papaya startup...')
  40. if (true) { // window.papayaContainers && window.papayaContainers[0]) {
  41. console.log('Great, Papaya started!');
  42. papaya.Container.startPapaya();
  43. //papaya.Container.addImage(0, big.buffer);
  44. document.body.id = "bod";
  45. document.body.style.background = "#555";
  46. papaya.Container.addViewer("bod", {
  47. 'binaryImages': [ big.buffer ],
  48. 'noNewFiles': true,
  49. });
  50. } else
  51. poll();
  52. }, 1000);
  53. };
  54. //setTimeout(poll, 10000);
  55. poll();
  56. });
  57. }
  58. class WBImageViewerPage extends Component {
  59. componentDidMount() {
  60. const { blobUrl, app } = this.props;
  61. const { arvHost, arvToken } = app.state;
  62. let prom = new Promise((accept, reject) => {
  63. const xhr = new XMLHttpRequest();
  64. xhr.open('GET', blobUrl);
  65. xhr.onreadystatechange = () => {
  66. if (xhr.readyState !== 4) return;
  67. if (xhr.status !== 200) reject(xhr);
  68. else accept(xhr);
  69. };
  70. xhr.responseType = 'blob';
  71. xhr.send();
  72. });
  73. prom = prom.then(xhr => xhr.response.text());
  74. prom = prom.then(data => {
  75. data = JSON.parse(data);
  76. downloadFile(arvHost, arvToken, data.file);
  77. });
  78. }
  79. render() {
  80. return (
  81. <div>
  82. <script language="javascript" src="/js/papaya.js"></script>
  83. <div id="papaya" style="width: auto; height: 100%; margin: 0;"></div>
  84. </div>
  85. );
  86. }
  87. }
  88. export default WBImageViewerPage;