-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements and bug fixes #87
Changes from 3 commits
dac6865
0207e91
62f3e0a
b0ed584
7dd098a
f2bd855
6900516
f1deec2
8bf56b1
6a96909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,45 @@ | ||
import { Router } from "express"; | ||
import { dbConnect, unescapeObjectKeys } from "../db/utils"; | ||
import { AdapterStats } from "../global/adapter-stats"; | ||
import { AdapterStats, AdapterVersions } from "../global/adapter-stats"; | ||
import { Statistics } from "../global/iobroker"; | ||
|
||
const router = Router(); | ||
|
||
router.get("/api/adapter/:name/stats", async function (req, res) { | ||
router.get("/api/adapter/:name/stats/now", async function (req, res) { | ||
try { | ||
const { name } = req.params; | ||
const db = await dbConnect(); | ||
const rawStatistics = db.rawStatistics(); | ||
|
||
const stats = await rawStatistics | ||
.find() | ||
.project<Statistics>({ | ||
adapters: { [name]: 1 }, | ||
versions: { [name]: 1 }, | ||
Check failure Code scanning / CodeQL Remote property injection High
A property name to write to depends on a
user-provided value Error loading related location Loading Check failure Code scanning / CodeQL Remote property injection High
A property name to write to depends on a
user-provided value Error loading related location Loading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name is now checked against some regexes that ensure it can only be a valid adapter name. These names can't be used for prototype pollution or similar attacks. |
||
date: 1, | ||
Check failure Code scanning / CodeQL Remote property injection High
A property name to write to depends on a
user-provided value Error loading related location Loading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name is now checked against some regexes that ensure it can only be a valid adapter name. These names can't be used for prototype pollution or similar attacks. |
||
_id: 0, | ||
}) | ||
.sort({ date: -1 }) | ||
.limit(1) | ||
.toArray(); | ||
if (stats.length === 0) { | ||
res.status(404).send(`Adapter ${name} not found`); | ||
|
||
return; | ||
} | ||
|
||
const stat = unescapeObjectKeys(stats[0]); | ||
const versions: AdapterVersions = { | ||
total: stat.adapters[name] ?? 0, | ||
versions: stat.versions[name] ?? {}, | ||
}; | ||
res.send(versions); | ||
} catch (error: any) { | ||
console.error(error); | ||
res.status(500).send(error.message || error); | ||
|
||
} | ||
}); | ||
|
||
router.get("/api/adapter/:name/stats/history", async function (req, res) { | ||
try { | ||
const { name } = req.params; | ||
const db = await dbConnect(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Chart from "react-google-charts"; | ||
import { Box, CircularProgress, Typography } from "@mui/material"; | ||
import { useAdapter } from "../../../contexts/AdapterContext"; | ||
import { useEffect, useState } from "react"; | ||
import { getCurrentVersions } from "../../../lib/ioBroker"; | ||
|
||
type GraphData = [string, string | number][]; | ||
|
||
export function CurrentVersions() { | ||
const { name } = useAdapter(); | ||
const [graphData, setGraphData] = useState<GraphData>(); | ||
|
||
useEffect(() => { | ||
setGraphData(undefined); | ||
const loadHistory = async () => { | ||
const stats = await getCurrentVersions(name); | ||
const data: GraphData = [["Version", "Count"]]; | ||
for (const [version, count] of Object.entries( | ||
stats.versions, | ||
).reverse()) { | ||
data.push([version, count]); | ||
} | ||
setGraphData(data); | ||
}; | ||
loadHistory().catch((e) => { | ||
console.error(e); | ||
setGraphData(undefined); | ||
}); | ||
}, [name]); | ||
|
||
return ( | ||
<Box> | ||
<Typography variant="h6" gutterBottom> | ||
Currently installed versions | ||
</Typography> | ||
<Chart | ||
width="100%" | ||
height="300px" | ||
chartType="PieChart" | ||
loader={<CircularProgress size="200px" />} | ||
data={graphData} | ||
options={{ | ||
is3D: true, | ||
backgroundColor: "transparent", | ||
sliceVisibilityThreshold: 0.05, | ||
/*colors: [ | ||
iconStyles.error.color, | ||
iconStyles.warning.color, | ||
iconStyles.check.color, | ||
],*/ | ||
}} | ||
/> | ||
</Box> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Paper } from "@mui/material"; | ||
import { VersionHistory } from "./VersionHistory"; | ||
import { CurrentVersions } from "./CurrentVersions"; | ||
|
||
export function Statistics() { | ||
return ( | ||
<> | ||
<Paper sx={{ padding: 2 }}> | ||
<CurrentVersions /> | ||
</Paper> | ||
<Paper sx={{ padding: 2, marginTop: 2 }}> | ||
<VersionHistory /> | ||
</Paper> | ||
</> | ||
); | ||
} |
Check failure
Code scanning / CodeQL
Remote property injection High