feat(app): stats added in to check if build in last build and also if theres a pending file
This commit is contained in:
34
app/src/internal/system/routes/stats.ts
Normal file
34
app/src/internal/system/routes/stats.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Router } from "express";
|
||||
import { tryCatch } from "../../../pkg/utils/tryCatch.js";
|
||||
import { db } from "../../../pkg/db/db.js";
|
||||
import {
|
||||
serverStats,
|
||||
type ServerStats,
|
||||
} from "../../../pkg/db/schema/serverstats.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { format } from "date-fns-tz";
|
||||
import { checkBuildUpdate } from "../utlis/checkForBuild.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /health
|
||||
router.get("/", async (req, res) => {
|
||||
const { data, error } = await tryCatch(
|
||||
db.select().from(serverStats).where(eq(serverStats.id, "serverStats"))
|
||||
);
|
||||
|
||||
if (error || !data) {
|
||||
res.status(400).json({ error: error });
|
||||
}
|
||||
|
||||
const statData = data as ServerStats[];
|
||||
res.json({
|
||||
status: "ok",
|
||||
uptime: process.uptime(),
|
||||
build: statData[0]?.build,
|
||||
pendingUpdateFile: await checkBuildUpdate(["."]),
|
||||
lastUpdate: format(statData[0].lastUpdate!, "MM/dd/yyyy HH:mm"),
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user