mirror of
https://github.com/joeseesun/wechat-radar.git
synced 2026-09-11 07:28:30 +09:00
Initial open source release
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db } from '@/lib/db';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
const dataDir = process.env.WECHAT_RADAR_DATA_DIR ?? join(homedir(), '.wechat-radar');
|
||||
const dbPath = join(dataDir, 'radar.db');
|
||||
const dbSize = existsSync(dbPath) ? statSync(dbPath).size : 0;
|
||||
const counts = {
|
||||
groups: (db().prepare('SELECT COUNT(*) AS n FROM groups').get() as { n: number }).n,
|
||||
messages: (db().prepare('SELECT COUNT(*) AS n FROM messages').get() as { n: number }).n,
|
||||
daily_stats: (db().prepare('SELECT COUNT(*) AS n FROM daily_stats').get() as { n: number }).n,
|
||||
sync_state: (db().prepare('SELECT COUNT(*) AS n FROM sync_state').get() as { n: number }).n,
|
||||
};
|
||||
const topGroups = db().prepare(`
|
||||
SELECT chatroom_id, COUNT(*) AS n FROM messages GROUP BY chatroom_id ORDER BY n DESC LIMIT 5
|
||||
`).all();
|
||||
return NextResponse.json({ dataDir, dbPath, dbSize, counts, topGroups });
|
||||
}
|
||||
Reference in New Issue
Block a user