mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-08-21 15:06:37 +00:00
Update DNS metrics charts and API to include dynamic date ranges and improved data fetching.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/288dfb12-98b8-4936-9b81-c64cee571edd.jpg
This commit is contained in:
@@ -743,6 +743,83 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// DNS Metrics
|
||||
app.get("/api/dns-metrics", requireRole(["admin", "manager", "user", "readonly"]), async (req, res) => {
|
||||
try {
|
||||
const metricType = req.query.type ? req.query.type as string : undefined;
|
||||
const startDate = req.query.startDate ? new Date(req.query.startDate as string) : undefined;
|
||||
const endDate = req.query.endDate ? new Date(req.query.endDate as string) : undefined;
|
||||
|
||||
const metrics = await storage.getDnsMetricsByType(
|
||||
metricType || "all",
|
||||
startDate,
|
||||
endDate
|
||||
);
|
||||
|
||||
res.json(metrics);
|
||||
} catch (error) {
|
||||
console.error("Error fetching DNS metrics:", error);
|
||||
res.status(500).json({ message: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/dns-metrics/domain/:domainId", requireRole(["admin", "manager", "user", "readonly"]), async (req, res) => {
|
||||
try {
|
||||
const domainId = req.params.domainId;
|
||||
const metricType = req.query.type ? req.query.type as string : undefined;
|
||||
const startDate = req.query.startDate ? new Date(req.query.startDate as string) : undefined;
|
||||
const endDate = req.query.endDate ? new Date(req.query.endDate as string) : undefined;
|
||||
|
||||
const metrics = await storage.getDnsMetricsByDomain(
|
||||
domainId,
|
||||
metricType,
|
||||
startDate,
|
||||
endDate
|
||||
);
|
||||
|
||||
res.json(metrics);
|
||||
} catch (error) {
|
||||
console.error("Error fetching domain DNS metrics:", error);
|
||||
res.status(500).json({ message: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/dns-metrics/record/:recordId", requireRole(["admin", "manager", "user", "readonly"]), async (req, res) => {
|
||||
try {
|
||||
const recordId = req.params.recordId;
|
||||
const metricType = req.query.type ? req.query.type as string : undefined;
|
||||
const startDate = req.query.startDate ? new Date(req.query.startDate as string) : undefined;
|
||||
const endDate = req.query.endDate ? new Date(req.query.endDate as string) : undefined;
|
||||
|
||||
const metrics = await storage.getDnsMetricsByRecord(
|
||||
recordId,
|
||||
metricType,
|
||||
startDate,
|
||||
endDate
|
||||
);
|
||||
|
||||
res.json(metrics);
|
||||
} catch (error) {
|
||||
console.error("Error fetching record DNS metrics:", error);
|
||||
res.status(500).json({ message: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/dns-metrics", requireRole(["admin", "manager"]), async (req, res) => {
|
||||
try {
|
||||
const validatedData = insertDnsMetricSchema.parse(req.body);
|
||||
const metric = await storage.addDnsMetric(validatedData);
|
||||
res.status(201).json(metric);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
res.status(400).json({ message: "Validation error", errors: error.errors });
|
||||
} else {
|
||||
console.error("Error creating DNS metric:", error);
|
||||
res.status(500).json({ message: "Internal server error" });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Webhooks
|
||||
app.get("/api/webhooks", requireRole(["admin", "manager"]), async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user