Fix for firmware GETs, longer timeout

This commit is contained in:
Charles
2021-09-17 18:27:53 -04:00
parent b4b74c9949
commit e440d10bce
5 changed files with 107 additions and 56 deletions

50
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ucentral-client",
"version": "2.1.0",
"version": "2.1.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ucentral-client",
"version": "2.1.0",
"version": "2.1.9",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
@@ -32,7 +32,7 @@
"react-tooltip": "^4.2.21",
"react-widgets": "^5.1.1",
"sass": "^1.35.1",
"ucentral-libs": "^0.8.82",
"ucentral-libs": "^0.9.16",
"uuid": "^8.3.2"
},
"devDependencies": {
@@ -14812,29 +14812,30 @@
}
},
"node_modules/ucentral-libs": {
"version": "0.8.82",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-0.8.82.tgz",
"integrity": "sha512-b6NUyK3vLm49tKs9HZXodBLMhn+SRZ6OragtF1j9GZ8UZpIJL3gB+Tfo576CUmgKW6U14GOplTPWQHGWZFEGjg==",
"engines": {
"node": ">=10"
},
"peerDependencies": {
"version": "0.9.16",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-0.9.16.tgz",
"integrity": "sha512-Bmh79uvf7vny/xIJ7hrObZmjAKxovzycFxq8T2ZYDUJF/ZK/n+ZBZJz+1m57YmwIEOUTYZ+DavIOgST4K4uB2Q==",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
"@coreui/icons-react": "^1.1.0",
"@coreui/react": "^3.4.6",
"@coreui/react-chartjs": "^1.1.0",
"lodash": "^4.17.21",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-flow-renderer": "^9.6.6",
"react-paginate": "^7.1.3",
"react-router-dom": "^5.2.0",
"react-select": "^4.3.1",
"react-tooltip": "^4.2.21",
"sass": "^1.35.1",
"uuid": "^8.3.2"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
},
"node_modules/unbox-primitive": {
@@ -27652,10 +27653,23 @@
}
},
"ucentral-libs": {
"version": "0.8.82",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-0.8.82.tgz",
"integrity": "sha512-b6NUyK3vLm49tKs9HZXodBLMhn+SRZ6OragtF1j9GZ8UZpIJL3gB+Tfo576CUmgKW6U14GOplTPWQHGWZFEGjg==",
"requires": {}
"version": "0.9.16",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-0.9.16.tgz",
"integrity": "sha512-Bmh79uvf7vny/xIJ7hrObZmjAKxovzycFxq8T2ZYDUJF/ZK/n+ZBZJz+1m57YmwIEOUTYZ+DavIOgST4K4uB2Q==",
"requires": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
"@coreui/icons-react": "^1.1.0",
"@coreui/react": "^3.4.6",
"@coreui/react-chartjs": "^1.1.0",
"lodash": "^4.17.21",
"react-flow-renderer": "^9.6.6",
"react-paginate": "^7.1.3",
"react-router-dom": "^5.2.0",
"react-select": "^4.3.1",
"react-tooltip": "^4.2.21",
"uuid": "^8.3.2"
}
},
"unbox-primitive": {
"version": "1.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "2.1.0",
"version": "2.1.9",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
@@ -26,7 +26,7 @@
"react-tooltip": "^4.2.21",
"react-widgets": "^5.1.1",
"sass": "^1.35.1",
"ucentral-libs": "^0.8.82",
"ucentral-libs": "^0.9.16",
"uuid": "^8.3.2"
},
"main": "index.js",

View File

@@ -1,6 +1,7 @@
/* eslint-disable no-await-in-loop */
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { DeviceFirmwareModal as Modal, useAuth } from 'ucentral-libs';
import { DeviceFirmwareModal as Modal, useAuth, useToast } from 'ucentral-libs';
import axiosInstance from 'utils/axiosInstance';
import { useTranslation } from 'react-i18next';
@@ -12,37 +13,59 @@ const DeviceFirmwareModal = ({
upgradeStatus,
}) => {
const { t } = useTranslation();
const { addToast } = useToast();
const { currentToken, endpoints } = useAuth();
const [loading, setLoading] = useState(false);
const [firmwareVersions, setFirmwareVersions] = useState([]);
const getFirmwareList = () => {
setLoading(true);
const getPartialFirmware = async (offset) => {
const headers = {
Accept: 'application/json',
Authorization: `Bearer ${currentToken}`,
};
axiosInstance
.get(`${endpoints.ucentralfms}/api/v1/firmwares?deviceType=${device.compatible}`, {
headers,
})
.then((response) => {
const sortedFirmware = response.data.firmwares.sort((a, b) => {
const firstDate = a.imageDate;
const secondDate = b.imageDate;
if (firstDate < secondDate) return 1;
return firstDate > secondDate ? -1 : 0;
});
setFirmwareVersions(sortedFirmware);
setLoading(false);
})
return axiosInstance
.get(
`${endpoints.ucentralfms}/api/v1/firmwares?deviceType=${device.compatible}&limit=500&offset=${offset}`,
{
headers,
},
)
.then((response) => response.data.firmwares)
.catch(() => {
setLoading(false);
addToast({
title: t('common.error'),
body: t('common.general_error'),
color: 'danger',
autohide: true,
});
return [];
});
};
const getFirmwareList = async () => {
setLoading(true);
const allFirmwares = [];
let continueFirmware = true;
let i = 1;
while (continueFirmware) {
const newFirmwares = await getPartialFirmware(i);
if (newFirmwares === null || newFirmwares.length === 0) continueFirmware = false;
allFirmwares.push(...newFirmwares);
i += 500;
}
const sortedFirmware = allFirmwares.sort((a, b) => {
const firstDate = a.imageDate;
const secondDate = b.imageDate;
if (firstDate < secondDate) return 1;
return firstDate > secondDate ? -1 : 0;
});
setFirmwareVersions(sortedFirmware);
setLoading(false);
};
const upgradeToVersion = (uri) => {
setUpgradeStatus({
loading: true,

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
import React, { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import axiosInstance from 'utils/axiosInstance';
@@ -48,42 +49,55 @@ const FirmwareListPage = () => {
filterFirmware(firmware, !displayDev);
};
const getFirmware = (deviceType) => {
setLoading(true);
const getPartialFirmware = async (deviceType, offset) => {
const headers = {
Accept: 'application/json',
Authorization: `Bearer ${currentToken}`,
};
axiosInstance
return axiosInstance
.get(
`${endpoints.ucentralfms}/api/v1/firmwares?deviceType=${deviceType ?? selectedDeviceType}`,
`${endpoints.ucentralfms}/api/v1/firmwares?deviceType=${deviceType}&limit=500&offset=${offset}`,
{
headers,
},
)
.then((response) => {
const sortedFirmware = response.data.firmwares.sort((a, b) => {
const firstDate = a.imageDate;
const secondDate = b.imageDate;
if (firstDate < secondDate) return 1;
return firstDate > secondDate ? -1 : 0;
});
setFirmware(sortedFirmware);
filterFirmware(sortedFirmware, displayDev);
})
.then((response) => response.data.firmwares)
.catch(() => {
setLoading(false);
addToast({
title: t('common.error'),
body: t('common.general_error'),
color: 'danger',
autohide: true,
});
return [];
});
};
const getFirmware = async (deviceType) => {
setLoading(true);
const allFirmwares = [];
let continueFirmware = true;
let i = 1;
while (continueFirmware) {
const newFirmwares = await getPartialFirmware(deviceType ?? selectedDeviceType, i);
if (newFirmwares === null || newFirmwares.length === 0) continueFirmware = false;
allFirmwares.push(...newFirmwares);
i += 500;
}
const sortedFirmware = allFirmwares.sort((a, b) => {
const firstDate = a.imageDate;
const secondDate = b.imageDate;
if (firstDate < secondDate) return 1;
return firstDate > secondDate ? -1 : 0;
});
setFirmware(sortedFirmware);
filterFirmware(sortedFirmware, displayDev);
setLoading(false);
};
const getDeviceTypes = () => {
setLoading(true);

View File

@@ -8,7 +8,7 @@ axiosRetry(axiosInstance, {
retryDelay: () => axiosRetry.exponentialDelay,
});
axiosInstance.defaults.timeout = 30000;
axiosInstance.defaults.timeout = 60000;
axiosInstance.defaults.headers.get.Accept = 'application/json';
axiosInstance.defaults.headers.post.Accept = 'application/json';