Files
Admin_dash/lib/visitors-db.ts
Shivam Patel d5ab2db926 Wire up visitor metrics from webserver DB and fix uptime monitoring
- Read visitors from /server_storage/visitors.db (webserver's DB) instead of
  admin dash's own table; geoip lookups at query time for globe markers
- Globe card now shows 24h, 7d, and all-time unique visitor counts
- Uptime monitor: Nextcloud via host.docker.internal for Docker networking,
  Website and Gitea monitored on public domains
- UptimeCard uses real hourly history bars instead of Math.random() mock
- docker-compose: mount /server_storage:ro, add extra_hosts for Linux compat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 00:50:40 -05:00

26 lines
677 B
TypeScript

import sqlite3 from 'sqlite3';
import { open, Database } from 'sqlite';
let db: Database | null = null;
/**
* Opens a read-only connection to the webserver's visitors.db.
* Returns null if the DB doesn't exist yet (webserver hasn't created it).
* Retries on each call until the DB becomes available.
*/
export async function getVisitorsDb(): Promise<Database | null> {
if (db) return db;
try {
db = await open({
filename: '/server_storage/visitors.db',
driver: sqlite3.Database,
mode: sqlite3.OPEN_READONLY,
});
return db;
} catch {
// DB doesn't exist yet — don't cache the failure so we retry next time
return null;
}
}