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 { isWebUri } from 'valid-url';
|
||||
import PouchDB from 'pouchdb';
|
||||
import { sleep } from '../utils/async.js';
|
||||
// import createDebug from 'debug';
|
||||
// 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 {
|
||||
static propTypes = {
|
||||
dispatch: PropTypes.func,
|
||||
@ -29,7 +38,7 @@ class AuthImage extends React.Component {
|
||||
const headers = {
|
||||
Authorization: `Basic ${btoa(`${token}:${password}`)}`
|
||||
};
|
||||
fetch(filteredSrc, { headers })
|
||||
recursiveFetch(filteredSrc, { headers })
|
||||
.then(response => response.blob())
|
||||
.then(blob => this.setState({ src: URL.createObjectURL(blob) }));
|
||||
} else {
|
||||
|
@ -1,3 +1,7 @@
|
||||
export function sleep(timeout) {
|
||||
return new Promise(resolve => setTimeout(resolve), timeout);
|
||||
}
|
||||
|
||||
export function recursivePromiseApply(object, promises = [], first = true) {
|
||||
for (const key in object) {
|
||||
const value = object[key];
|
||||
|
Loading…
Reference in New Issue
Block a user