🐛 Fix dash. api (#1024)

This commit is contained in:
Manuel
2023-06-09 20:10:47 +02:00
committed by GitHub
parent 240747307d
commit ba659b6247
3 changed files with 14 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
? dashDotUrl.substring(0, dashDotUrl.length - 1)
: dashDotUrl;
const response = await axios.get(`${url}/info`);
// Return the response
return res.status(200).json(response.data);
}

View File

@@ -9,8 +9,9 @@ interface DashDotCompactNetworkProps {
export interface DashDotInfo {
storage: {
layout: { size: number }[];
};
size: number;
disks: { device: string; brand: string; type: string }[];
}[];
network: {
speedUp: number;
speedDown: number;

View File

@@ -17,11 +17,10 @@ export const DashDotCompactStorage = ({ info, widgetId }: DashDotCompactStorageP
const { data: storageLoad } = useDashDotStorage(widgetId);
const totalUsed = calculateTotalLayoutSize({
layout: storageLoad?.layout ?? [],
key: 'load',
layout: storageLoad ?? [],
});
const totalSize = calculateTotalLayoutSize({
layout: info?.storage?.layout ?? [],
layout: info?.storage ?? [],
key: 'size',
});
@@ -44,11 +43,16 @@ const calculateTotalLayoutSize = <TLayoutItem,>({
layout,
key,
}: 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> {
layout: TLayoutItem[];
key: keyof TLayoutItem;
key?: keyof TLayoutItem;
}
const useDashDotStorage = (widgetId: string) => {
@@ -71,9 +75,5 @@ async function fetchDashDotStorageLoad(configName: string | undefined, widgetId:
if (!configName) throw new Error('configName is undefined');
return (await (
await axios.get('/api/modules/dashdot/storage', { params: { configName, widgetId } })
).data) as DashDotStorageLoad;
}
interface DashDotStorageLoad {
layout: { load: number }[];
).data) as number[];
}