mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-24 07:20:54 +01:00
🐛 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;
|
||||
const response = await axios.get(`${url}/info`);
|
||||
|
||||
// Return the response
|
||||
return res.status(200).json(response.data);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user