mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2025-01-05 17:33:49 +01:00
update fetch progress
This commit is contained in:
parent
f28722aec5
commit
4dc5e4849e
@ -2,7 +2,7 @@ import * as THREE from 'three';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'proptypes';
|
import PropTypes from 'proptypes';
|
||||||
import { centerGeometry, placeOnGround, createScene, fetchProgress, slice, TabTemplate } from './utils.js';
|
import { centerGeometry, placeOnGround, createScene, slice, TabTemplate } from './utils.js';
|
||||||
import injectSheet from 'react-jss';
|
import injectSheet from 'react-jss';
|
||||||
import RaisedButton from 'material-ui/RaisedButton';
|
import RaisedButton from 'material-ui/RaisedButton';
|
||||||
import FlatButton from 'material-ui/FlatButton';
|
import FlatButton from 'material-ui/FlatButton';
|
||||||
|
@ -84,20 +84,33 @@ export function createScene({ pixelRatio, muiTheme }) {
|
|||||||
return { editorControls, scene, mesh, camera, renderer, render, box, setSize, updateCanvas, focus };
|
return { editorControls, scene, mesh, camera, renderer, render, box, setSize, updateCanvas, focus };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchProgress(url, { method = 'get', headers = {}, body = {} } = {}, onProgress) {
|
export function fetchProgress(url, data = {}, onProgress) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = new Request(url, data);
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open(method, url);
|
|
||||||
if (headers) {
|
xhr.onload = () => {
|
||||||
for (const key in headers) {
|
const { status, statusText, responseURL: url } = xhr;
|
||||||
const header = headers[key];
|
resolve(new Response(xhr.response, { status, statusText, url }));
|
||||||
xhr.setRequestHeader(key, header);
|
}
|
||||||
}
|
xhr.onerror = () => reject(new TypeError('Network request failed'));
|
||||||
|
xhr.ontimeout = () => reject(new TypeError('Network request failed'));
|
||||||
|
|
||||||
|
xhr.open(request.method, url);
|
||||||
|
|
||||||
|
if (request.credentials === 'include') {
|
||||||
|
xhr.withCredentials = true
|
||||||
|
} else if (request.credentials === 'omit') {
|
||||||
|
xhr.withCredentials = false
|
||||||
}
|
}
|
||||||
xhr.onload = event => resolve(event.target.responseText);
|
|
||||||
xhr.onerror = reject;
|
|
||||||
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
|
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
|
||||||
xhr.send(body);
|
if (xhr.responseType) xhr.responseType = 'blob';
|
||||||
|
|
||||||
|
request.headers.forEach((value, name) => {
|
||||||
|
xhr.setRequestHeader(name, value)
|
||||||
|
});
|
||||||
|
|
||||||
|
xhr.send(data.body);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user