🐛 Fix dash. api (#1024)
This commit is contained in:
@@ -44,6 +44,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
? dashDotUrl.substring(0, dashDotUrl.length - 1)
|
? dashDotUrl.substring(0, dashDotUrl.length - 1)
|
||||||
: dashDotUrl;
|
: dashDotUrl;
|
||||||
const response = await axios.get(`${url}/info`);
|
const response = await axios.get(`${url}/info`);
|
||||||
|
|
||||||
// Return the response
|
// Return the response
|
||||||
return res.status(200).json(response.data);
|
return res.status(200).json(response.data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ interface DashDotCompactNetworkProps {
|
|||||||
|
|
||||||
export interface DashDotInfo {
|
export interface DashDotInfo {
|
||||||
storage: {
|
storage: {
|
||||||
layout: { size: number }[];
|
size: number;
|
||||||
};
|
disks: { device: string; brand: string; type: string }[];
|
||||||
|
}[];
|
||||||
network: {
|
network: {
|
||||||
speedUp: number;
|
speedUp: number;
|
||||||
speedDown: number;
|
speedDown: number;
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ export const DashDotCompactStorage = ({ info, widgetId }: DashDotCompactStorageP
|
|||||||
const { data: storageLoad } = useDashDotStorage(widgetId);
|
const { data: storageLoad } = useDashDotStorage(widgetId);
|
||||||
|
|
||||||
const totalUsed = calculateTotalLayoutSize({
|
const totalUsed = calculateTotalLayoutSize({
|
||||||
layout: storageLoad?.layout ?? [],
|
layout: storageLoad ?? [],
|
||||||
key: 'load',
|
|
||||||
});
|
});
|
||||||
const totalSize = calculateTotalLayoutSize({
|
const totalSize = calculateTotalLayoutSize({
|
||||||
layout: info?.storage?.layout ?? [],
|
layout: info?.storage ?? [],
|
||||||
key: 'size',
|
key: 'size',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,11 +43,16 @@ const calculateTotalLayoutSize = <TLayoutItem,>({
|
|||||||
layout,
|
layout,
|
||||||
key,
|
key,
|
||||||
}: CalculateTotalLayoutSizeProps<TLayoutItem>) =>
|
}: CalculateTotalLayoutSizeProps<TLayoutItem>) =>
|
||||||
layout.reduce((total, current) => total + (current[key] as number), 0);
|
layout.reduce((total, current) => {
|
||||||
|
if (key) {
|
||||||
|
return total + (current[key] as number);
|
||||||
|
}
|
||||||
|
return total + (current as number);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
interface CalculateTotalLayoutSizeProps<TLayoutItem> {
|
interface CalculateTotalLayoutSizeProps<TLayoutItem> {
|
||||||
layout: TLayoutItem[];
|
layout: TLayoutItem[];
|
||||||
key: keyof TLayoutItem;
|
key?: keyof TLayoutItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useDashDotStorage = (widgetId: string) => {
|
const useDashDotStorage = (widgetId: string) => {
|
||||||
@@ -71,9 +75,5 @@ async function fetchDashDotStorageLoad(configName: string | undefined, widgetId:
|
|||||||
if (!configName) throw new Error('configName is undefined');
|
if (!configName) throw new Error('configName is undefined');
|
||||||
return (await (
|
return (await (
|
||||||
await axios.get('/api/modules/dashdot/storage', { params: { configName, widgetId } })
|
await axios.get('/api/modules/dashdot/storage', { params: { configName, widgetId } })
|
||||||
).data) as DashDotStorageLoad;
|
).data) as number[];
|
||||||
}
|
|
||||||
|
|
||||||
interface DashDotStorageLoad {
|
|
||||||
layout: { load: number }[];
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user