mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-01-02 08:03:48 +01:00
recursive fetch in authimage
This commit is contained in:
parent
6b6b860c4a
commit
5032018257
@ -3,9 +3,18 @@ import PropTypes from 'proptypes';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { isWebUri } from 'valid-url';
|
import { isWebUri } from 'valid-url';
|
||||||
import PouchDB from 'pouchdb';
|
import PouchDB from 'pouchdb';
|
||||||
|
import { sleep } from '../utils/async.js';
|
||||||
// import createDebug from 'debug';
|
// import createDebug from 'debug';
|
||||||
// const debug = createDebug('d3d:FileThumb');
|
// const debug = createDebug('d3d:FileThumb');
|
||||||
|
|
||||||
|
function recursiveFetch(url, options, timeout = 1000, retries = -1) {
|
||||||
|
return fetch(url, options).catch(async (error) => {
|
||||||
|
if (retries === 0) throw error;
|
||||||
|
await sleep(timeout);
|
||||||
|
return recursiveFetch(url, options, timeout, (retries === -1) ? retries : retries - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class AuthImage extends React.Component {
|
class AuthImage extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
dispatch: PropTypes.func,
|
dispatch: PropTypes.func,
|
||||||
@ -29,7 +38,7 @@ class AuthImage extends React.Component {
|
|||||||
const headers = {
|
const headers = {
|
||||||
Authorization: `Basic ${btoa(`${token}:${password}`)}`
|
Authorization: `Basic ${btoa(`${token}:${password}`)}`
|
||||||
};
|
};
|
||||||
fetch(filteredSrc, { headers })
|
recursiveFetch(filteredSrc, { headers })
|
||||||
.then(response => response.blob())
|
.then(response => response.blob())
|
||||||
.then(blob => this.setState({ src: URL.createObjectURL(blob) }));
|
.then(blob => this.setState({ src: URL.createObjectURL(blob) }));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
export function sleep(timeout) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve), timeout);
|
||||||
|
}
|
||||||
|
|
||||||
export function recursivePromiseApply(object, promises = [], first = true) {
|
export function recursivePromiseApply(object, promises = [], first = true) {
|
||||||
for (const key in object) {
|
for (const key in object) {
|
||||||
const value = object[key];
|
const value = object[key];
|
||||||
|
Loading…
Reference in New Issue
Block a user