style: clean up code with prettier and eslint
This commit is contained in:
1 parent
60278b9e71
commit
fb8e77bb68
378 files changed
+22407
-20689
No files matched your search
@@ -1,32 +1,32 @@
|
||||
import { redirect } from 'next/navigation'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { redirect } from "next/navigation";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function EmulatorErrorsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<Record<string, string>>
|
||||
searchParams: Promise<Record<string, string>>;
|
||||
}) {
|
||||
const { session, permissions } = await getAdminContext()
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.DEVOPS_VIEW, session.user.rank)) {
|
||||
redirect('/admin')
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const params = await searchParams
|
||||
const page = Math.max(1, Number(params.page) || 1)
|
||||
const perPage = 50
|
||||
const params = await searchParams;
|
||||
const page = Math.max(1, Number(params.page) || 1);
|
||||
const perPage = 50;
|
||||
|
||||
const [errors, total] = await Promise.all([
|
||||
prisma.emulatorErrors.findMany({
|
||||
orderBy: { id: 'desc' },
|
||||
orderBy: { id: "desc" },
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
}),
|
||||
prisma.emulatorErrors.count(),
|
||||
])
|
||||
]);
|
||||
|
||||
const lastPage = Math.ceil(total / perPage)
|
||||
const lastPage = Math.ceil(total / perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -52,7 +52,7 @@ export default async function EmulatorErrorsPage({
|
||||
</span>
|
||||
</div>
|
||||
<pre className="text-xs whitespace-pre-wrap break-all font-mono bg-muted p-2 rounded">
|
||||
{Buffer.from(error.stacktrace).toString('utf-8')}
|
||||
{Buffer.from(error.stacktrace).toString("utf-8")}
|
||||
</pre>
|
||||
</div>
|
||||
))}
|
||||
@@ -79,5 +79,5 @@ export default async function EmulatorErrorsPage({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1,55 +1,45 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { RefreshCw } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function HealthCheckClient() {
|
||||
const [status, setStatus] = useState<'checking' | 'online' | 'offline'>('checking')
|
||||
const [checking, setChecking] = useState(false)
|
||||
const [status, setStatus] = useState<"checking" | "online" | "offline">("checking");
|
||||
const [checking, setChecking] = useState(false);
|
||||
|
||||
async function checkEmulator() {
|
||||
setChecking(true)
|
||||
setStatus('checking')
|
||||
setChecking(true);
|
||||
setStatus("checking");
|
||||
try {
|
||||
const res = await fetch('/api/admin/devops/health')
|
||||
const res = await fetch("/api/admin/devops/health");
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setStatus(data.emulator ? 'online' : 'offline')
|
||||
const data = await res.json();
|
||||
setStatus(data.emulator ? "online" : "offline");
|
||||
} else {
|
||||
setStatus('offline')
|
||||
setStatus("offline");
|
||||
}
|
||||
} catch {
|
||||
setStatus('offline')
|
||||
setStatus("offline");
|
||||
} finally {
|
||||
setChecking(false)
|
||||
setChecking(false);
|
||||
}
|
||||
}
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: explicitly chosen here, see surrounding code
|
||||
useEffect(() => {
|
||||
checkEmulator()
|
||||
}, [])
|
||||
checkEmulator();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge
|
||||
variant={
|
||||
status === 'online' ? 'default' : status === 'offline' ? 'destructive' : 'secondary'
|
||||
}
|
||||
>
|
||||
{status === 'checking' ? 'Checking...' : status === 'online' ? 'Online' : 'Offline'}
|
||||
<Badge variant={status === "online" ? "default" : status === "offline" ? "destructive" : "secondary"}>
|
||||
{status === "checking" ? "Checking..." : status === "online" ? "Online" : "Offline"}
|
||||
</Badge>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6"
|
||||
onClick={checkEmulator}
|
||||
disabled={checking}
|
||||
>
|
||||
<RefreshCw className={`h-3 w-3 ${checking ? 'animate-spin' : ''}`} />
|
||||
<Button variant="ghost" size="icon" className="h-6 w-6" onClick={checkEmulator} disabled={checking}>
|
||||
<RefreshCw className={`h-3 w-3 ${checking ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1,61 +1,61 @@
|
||||
import { AlertTriangle, Database, HeartPulse, Server } from 'lucide-react'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { HealthCheckClient } from './health-check-client'
|
||||
import { AlertTriangle, Database, HeartPulse, Server } from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { HealthCheckClient } from "./health-check-client";
|
||||
|
||||
async function getDevOpsData() {
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
const dayAgo = now - 86400
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const dayAgo = now - 86400;
|
||||
|
||||
// DB health — simple count query
|
||||
let dbStatus: 'healthy' | 'error' = 'healthy'
|
||||
let dbLatency = 0
|
||||
let dbStatus: "healthy" | "error" = "healthy";
|
||||
let dbLatency = 0;
|
||||
try {
|
||||
const start = Date.now()
|
||||
await prisma.user.count({ take: 1 })
|
||||
dbLatency = Date.now() - start
|
||||
const start = Date.now();
|
||||
await prisma.user.count({ take: 1 });
|
||||
dbLatency = Date.now() - start;
|
||||
} catch {
|
||||
dbStatus = 'error'
|
||||
dbStatus = "error";
|
||||
}
|
||||
|
||||
// Recent emulator errors
|
||||
const recentErrors = await prisma.emulatorErrors.findMany({
|
||||
orderBy: { id: 'desc' },
|
||||
orderBy: { id: "desc" },
|
||||
take: 20,
|
||||
})
|
||||
});
|
||||
|
||||
const errorsToday = await prisma.emulatorErrors.count({
|
||||
where: { timestamp: { gte: dayAgo } },
|
||||
})
|
||||
});
|
||||
|
||||
// Emulator settings (version info)
|
||||
const emuVersion = await prisma.emulatorSettings.findFirst({
|
||||
where: { key: 'version' },
|
||||
})
|
||||
where: { key: "version" },
|
||||
});
|
||||
|
||||
// Online user count as proxy for emulator health
|
||||
const onlineUsers = await prisma.user.count({ where: { online: '1' } })
|
||||
const onlineUsers = await prisma.user.count({ where: { online: "1" } });
|
||||
|
||||
return {
|
||||
dbStatus,
|
||||
dbLatency,
|
||||
recentErrors,
|
||||
errorsToday,
|
||||
emuVersion: emuVersion?.value ?? 'Unknown',
|
||||
emuVersion: emuVersion?.value ?? "Unknown",
|
||||
onlineUsers,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default async function DevOpsPage() {
|
||||
const { session, permissions } = await getAdminContext()
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.DEVOPS_VIEW, session.user.rank)) {
|
||||
redirect('/admin')
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const data = await getDevOpsData()
|
||||
const data = await getDevOpsData();
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -72,8 +72,8 @@ export default async function DevOpsPage() {
|
||||
<Database className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Badge variant={data.dbStatus === 'healthy' ? 'default' : 'destructive'}>
|
||||
{data.dbStatus === 'healthy' ? 'Healthy' : 'Error'}
|
||||
<Badge variant={data.dbStatus === "healthy" ? "default" : "destructive"}>
|
||||
{data.dbStatus === "healthy" ? "Healthy" : "Error"}
|
||||
</Badge>
|
||||
<p className="text-xs text-muted-foreground mt-1">Latency: {data.dbLatency}ms</p>
|
||||
</CardContent>
|
||||
@@ -134,7 +134,7 @@ export default async function DevOpsPage() {
|
||||
</span>
|
||||
</div>
|
||||
<pre className="text-xs whitespace-pre-wrap break-all font-mono text-destructive">
|
||||
{Buffer.from(error.stacktrace).toString('utf-8')}
|
||||
{Buffer.from(error.stacktrace).toString("utf-8")}
|
||||
</pre>
|
||||
</div>
|
||||
))}
|
||||
@@ -143,5 +143,5 @@ export default async function DevOpsPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user