This commit is contained in:
1 parent
21a61068fb
commit
60278b9e71
38 files changed
+3452
No files matched your search
@@ -0,0 +1,111 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { DataTable } from '@/components/admin/data-table'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import type { DataTableColumn, PaginatedResult } from '@/types'
|
||||
|
||||
interface AuditRow {
|
||||
id: number
|
||||
username: string
|
||||
action: string
|
||||
target: string
|
||||
targetId: number | null
|
||||
diff: string | null
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
function DiffCell({ diff }: { diff: string | null }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
if (!diff) return <span className="text-muted-foreground">-</span>
|
||||
|
||||
let parsed: Record<string, { from: unknown; to: unknown }>
|
||||
try {
|
||||
parsed = JSON.parse(diff)
|
||||
} catch {
|
||||
return <span className="text-muted-foreground">-</span>
|
||||
}
|
||||
|
||||
const keys = Object.keys(parsed)
|
||||
if (keys.length === 0) return <span className="text-muted-foreground">-</span>
|
||||
|
||||
const summary =
|
||||
keys.length === 1
|
||||
? `${keys[0]}: ${String(parsed[keys[0]].from ?? '∅')} → ${String(parsed[keys[0]].to ?? '∅')}`
|
||||
: `${keys.length} changes`
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-auto p-0 text-xs font-normal"
|
||||
onClick={() => setOpen(!open)}
|
||||
>
|
||||
{summary}
|
||||
</Button>
|
||||
{open && (
|
||||
<div className="mt-1 space-y-0.5 text-xs">
|
||||
{keys.map((k) => (
|
||||
<div key={k} className="flex gap-1">
|
||||
<span className="font-medium">{k}:</span>
|
||||
<span className="text-[var(--admin-error)] line-through">{String(parsed[k].from ?? '∅')}</span>
|
||||
<span>→</span>
|
||||
<span className="text-[var(--admin-success)]">{String(parsed[k].to ?? '∅')}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<AuditRow>[] = [
|
||||
{ key: 'id', label: 'ID', sortable: true },
|
||||
{ key: 'username', label: 'User', sortable: true },
|
||||
{
|
||||
key: 'action',
|
||||
label: 'Action',
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value)
|
||||
let variant: 'default' | 'secondary' | 'destructive' = 'secondary'
|
||||
if (v.includes('create') || v.includes('add')) variant = 'default'
|
||||
if (v.includes('delete') || v.includes('remove') || v.includes('ban')) variant = 'destructive'
|
||||
return <Badge variant={variant}>{v}</Badge>
|
||||
},
|
||||
},
|
||||
{ key: 'target', label: 'Target', sortable: true },
|
||||
{
|
||||
key: 'targetId',
|
||||
label: 'Target ID',
|
||||
render: (value) => <span>{value != null ? String(value) : '-'}</span>,
|
||||
},
|
||||
{
|
||||
key: 'diff',
|
||||
label: 'Details',
|
||||
render: (_value, row) => <DiffCell diff={row.diff} />,
|
||||
},
|
||||
{
|
||||
key: 'createdAt',
|
||||
label: 'Date',
|
||||
sortable: true,
|
||||
render: (value) => <span>{String(value) || 'N/A'}</span>,
|
||||
},
|
||||
]
|
||||
|
||||
interface AuditTableProps {
|
||||
data: PaginatedResult<AuditRow>
|
||||
}
|
||||
|
||||
export function AuditTable({ data }: AuditTableProps) {
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by action or target..."
|
||||
exportUrl="/api/admin/export?type=audit"
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function AuditLogsLoading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<Skeleton className="h-9 w-40" />
|
||||
<Skeleton className="h-5 w-64 mt-2" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-10 w-64" />
|
||||
<Skeleton className="h-10 w-24" />
|
||||
</div>
|
||||
<div className="rounded-md border">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div key={i} className="flex items-center gap-6 px-4 py-3 border-b last:border-0">
|
||||
<Skeleton className="h-4 w-12" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { redirect } from 'next/navigation'
|
||||
import { calcPagination, parseListParams } from '@/lib/admin-helpers'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { getAuditLogs } from '@/lib/services/audit'
|
||||
import { AuditTable } from './audit-table'
|
||||
|
||||
export default async function AuditLogsPage({
|
||||
params: paramsPromise,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<Record<string, string>>
|
||||
}) {
|
||||
await paramsPromise
|
||||
const { session, permissions } = await getAdminContext()
|
||||
if (!canAccess(permissions, PERMS.LOGS_VIEW, session.user.rank)) {
|
||||
redirect('/admin')
|
||||
}
|
||||
|
||||
const params = await searchParams
|
||||
const sp = new URLSearchParams(params)
|
||||
const { search, perPage, page } = parseListParams(sp)
|
||||
|
||||
const result = await getAuditLogs({ search, page, perPage })
|
||||
|
||||
const pagination = calcPagination(result.total, result.page, result.perPage)
|
||||
|
||||
const rows = result.rows.map((r) => ({
|
||||
id: r.id,
|
||||
username: r.username,
|
||||
action: r.action,
|
||||
target: r.target,
|
||||
targetId: r.targetId,
|
||||
diff: r.diff,
|
||||
createdAt: r.createdAt,
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Audit Logs</h1>
|
||||
<p className="text-muted-foreground">Track admin actions and changes</p>
|
||||
</div>
|
||||
|
||||
<AuditTable data={{ rows, ...pagination }} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
'use client'
|
||||
|
||||
import { DataTable } from '@/components/admin/data-table'
|
||||
import { formatTimestamp } from '@/lib/admin-helpers'
|
||||
import type { DataTableColumn, PaginatedResult } from '@/types'
|
||||
|
||||
interface ChatLogRow {
|
||||
id: number
|
||||
username: string
|
||||
message: string
|
||||
timestamp: number
|
||||
roomId: number
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<ChatLogRow>[] = [
|
||||
{ key: 'id', label: 'ID', sortable: true },
|
||||
{ key: 'username', label: 'User' },
|
||||
{
|
||||
key: 'message',
|
||||
label: 'Message',
|
||||
render: (value) => <span className="max-w-[300px] truncate block">{String(value)}</span>,
|
||||
},
|
||||
{
|
||||
key: 'timestamp',
|
||||
label: 'Time',
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
{ key: 'roomId', label: 'Room ID', sortable: true },
|
||||
]
|
||||
|
||||
interface ChatTableProps {
|
||||
data: PaginatedResult<ChatLogRow>
|
||||
}
|
||||
|
||||
export function ChatTable({ data }: ChatTableProps) {
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by username or message..."
|
||||
exportUrl="/api/admin/export?type=chatlogs"
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function ChatLogsLoading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<Skeleton className="h-9 w-40" />
|
||||
<Skeleton className="h-5 w-64 mt-2" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-10 w-64" />
|
||||
<Skeleton className="h-10 w-24" />
|
||||
</div>
|
||||
<div className="rounded-md border">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div key={i} className="flex items-center gap-6 px-4 py-3 border-b last:border-0">
|
||||
<Skeleton className="h-4 w-12" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { fetchAdminList } from '@/lib/admin-list'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { ChatTable } from './chat-table'
|
||||
|
||||
export default async function ChatLogsPage({
|
||||
params: paramsPromise,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<Record<string, string>>
|
||||
}) {
|
||||
const result = await fetchAdminList(
|
||||
{
|
||||
permission: PERMS.LOGS_VIEW,
|
||||
model: 'chatLog',
|
||||
searchFields: ['message', 'user.username'],
|
||||
defaultPerPage: 50,
|
||||
include: { user: { select: { username: true } } },
|
||||
mapRow: (l) => ({
|
||||
id: l.id,
|
||||
username: l.user.username,
|
||||
message: l.message,
|
||||
timestamp: l.timestamp,
|
||||
roomId: l.roomId,
|
||||
}),
|
||||
},
|
||||
paramsPromise,
|
||||
searchParams,
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Chat Logs</h1>
|
||||
<p className="text-muted-foreground">View in-game chat messages</p>
|
||||
</div>
|
||||
|
||||
<ChatTable
|
||||
data={{
|
||||
rows: result.rows,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
perPage: result.perPage,
|
||||
lastPage: result.lastPage,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
'use client'
|
||||
|
||||
import { DataTable } from '@/components/admin/data-table'
|
||||
import { formatTimestamp } from '@/lib/admin-helpers'
|
||||
import type { DataTableColumn, PaginatedResult } from '@/types'
|
||||
|
||||
interface CommandLogRow {
|
||||
id: number
|
||||
username: string
|
||||
command: string
|
||||
params: string
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<CommandLogRow>[] = [
|
||||
{ key: 'id', label: 'ID', sortable: true },
|
||||
{ key: 'username', label: 'User' },
|
||||
{ key: 'command', label: 'Command', sortable: true },
|
||||
{
|
||||
key: 'params',
|
||||
label: 'Params',
|
||||
render: (value) => (
|
||||
<span className="max-w-[200px] truncate block font-mono text-sm">{String(value) || '-'}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'timestamp',
|
||||
label: 'Time',
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
]
|
||||
|
||||
interface CommandsTableProps {
|
||||
data: PaginatedResult<CommandLogRow>
|
||||
}
|
||||
|
||||
export function CommandsTable({ data }: CommandsTableProps) {
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by username, command, or params..."
|
||||
exportUrl="/api/admin/export?type=commands"
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function CommandLogsLoading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<Skeleton className="h-9 w-40" />
|
||||
<Skeleton className="h-5 w-64 mt-2" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-10 w-64" />
|
||||
<Skeleton className="h-10 w-24" />
|
||||
</div>
|
||||
<div className="rounded-md border">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div key={i} className="flex items-center gap-6 px-4 py-3 border-b last:border-0">
|
||||
<Skeleton className="h-4 w-12" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { fetchAdminList } from '@/lib/admin-list'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { CommandsTable } from './commands-table'
|
||||
|
||||
export default async function CommandLogsPage({
|
||||
params: paramsPromise,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<Record<string, string>>
|
||||
}) {
|
||||
const result = await fetchAdminList(
|
||||
{
|
||||
permission: PERMS.LOGS_VIEW,
|
||||
model: 'commandLog',
|
||||
searchFields: ['command', 'params', 'user.username'],
|
||||
defaultPerPage: 50,
|
||||
include: { user: { select: { username: true } } },
|
||||
mapRow: (l) => ({
|
||||
id: l.id,
|
||||
username: l.user.username,
|
||||
command: l.command,
|
||||
params: l.params,
|
||||
timestamp: l.timestamp,
|
||||
}),
|
||||
},
|
||||
paramsPromise,
|
||||
searchParams,
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Command Logs</h1>
|
||||
<p className="text-muted-foreground">View in-game command usage</p>
|
||||
</div>
|
||||
|
||||
<CommandsTable
|
||||
data={{
|
||||
rows: result.rows,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
perPage: result.perPage,
|
||||
lastPage: result.lastPage,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function TradeLogsLoading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<Skeleton className="h-9 w-40" />
|
||||
<Skeleton className="h-5 w-64 mt-2" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-10 w-64" />
|
||||
<Skeleton className="h-10 w-24" />
|
||||
</div>
|
||||
<div className="rounded-md border">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div key={i} className="flex items-center gap-6 px-4 py-3 border-b last:border-0">
|
||||
<Skeleton className="h-4 w-12" />
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-5 w-16 rounded-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { fetchAdminList } from '@/lib/admin-list'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { TradesTable } from './trades-table'
|
||||
|
||||
export default async function TradeLogsPage({
|
||||
params: paramsPromise,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<Record<string, string>>
|
||||
}) {
|
||||
const result = await fetchAdminList(
|
||||
{
|
||||
permission: PERMS.LOGS_VIEW,
|
||||
model: 'trade',
|
||||
searchFields: ['userOne.username', 'userTwo.username'],
|
||||
defaultPerPage: 50,
|
||||
include: {
|
||||
userOne: { select: { username: true } },
|
||||
userTwo: { select: { username: true } },
|
||||
},
|
||||
mapRow: (t) => ({
|
||||
id: t.id,
|
||||
userOneName: t.userOne.username,
|
||||
userTwoName: t.userTwo.username,
|
||||
status: t.status,
|
||||
timestamp: t.timestamp,
|
||||
}),
|
||||
},
|
||||
paramsPromise,
|
||||
searchParams,
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Trade Logs</h1>
|
||||
<p className="text-muted-foreground">View in-game trade history</p>
|
||||
</div>
|
||||
|
||||
<TradesTable
|
||||
data={{
|
||||
rows: result.rows,
|
||||
total: result.total,
|
||||
page: result.page,
|
||||
perPage: result.perPage,
|
||||
lastPage: result.lastPage,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
'use client'
|
||||
|
||||
import { DataTable } from '@/components/admin/data-table'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { formatTimestamp } from '@/lib/admin-helpers'
|
||||
import type { DataTableColumn, PaginatedResult } from '@/types'
|
||||
|
||||
interface TradeLogRow {
|
||||
id: number
|
||||
userOneName: string
|
||||
userTwoName: string
|
||||
status: string
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<TradeLogRow>[] = [
|
||||
{ key: 'id', label: 'ID', sortable: true },
|
||||
{ key: 'userOneName', label: 'User One' },
|
||||
{ key: 'userTwoName', label: 'User Two' },
|
||||
{
|
||||
key: 'status',
|
||||
label: 'Status',
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value)
|
||||
const variant =
|
||||
v === 'completed' ? 'default' : v === 'cancelled' ? 'destructive' : 'secondary'
|
||||
return <Badge variant={variant}>{v || 'unknown'}</Badge>
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'timestamp',
|
||||
label: 'Time',
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
]
|
||||
|
||||
interface TradesTableProps {
|
||||
data: PaginatedResult<TradeLogRow>
|
||||
}
|
||||
|
||||
export function TradesTable({ data }: TradesTableProps) {
|
||||
return <DataTable data={data} columns={columns} searchPlaceholder="Search by username..." />
|
||||
}
|
||||
Reference in new issue
Block a user