2025-06-28 17:07:53 +00:00
|
|
|
import { DB_PATH } from "$lib/utils/constants";
|
2025-06-28 17:19:40 +00:00
|
|
|
import { Database, Statement } from "bun:sqlite";
|
2025-06-28 17:07:53 +00:00
|
|
|
|
2025-06-28 17:19:40 +00:00
|
|
|
export class SSLSnifferApp {
|
2025-06-28 17:07:53 +00:00
|
|
|
|
|
|
|
|
private static initialized = false
|
|
|
|
|
|
2025-06-28 21:52:44 +00:00
|
|
|
private static db: Database
|
2025-06-28 17:07:53 +00:00
|
|
|
|
|
|
|
|
// UGLY: should be more flexible
|
2025-06-28 21:52:44 +00:00
|
|
|
public static init() {
|
|
|
|
|
|
|
|
|
|
if (SSLSnifferApp.initialized) {
|
|
|
|
|
throw new Error("SSLSniffer has already been initialized")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SSLSnifferApp.db = SSLSnifferApp.initDatabase()
|
2025-06-28 17:19:40 +00:00
|
|
|
SSLSnifferApp.initialized = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-28 21:52:44 +00:00
|
|
|
public static prepare(query: string) {
|
|
|
|
|
return SSLSnifferApp.db.prepare(query)
|
2025-06-28 17:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static initDatabase() {
|
|
|
|
|
|
|
|
|
|
const db = new Database(
|
|
|
|
|
DB_PATH,
|
|
|
|
|
{
|
|
|
|
|
create: true,
|
|
|
|
|
strict: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Improve performance
|
|
|
|
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
|
|
|
return db
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-28 21:52:44 +00:00
|
|
|
private static closeDatabase(graceful?: boolean) {
|
|
|
|
|
|
2025-06-28 17:07:53 +00:00
|
|
|
if (!graceful) {
|
2025-06-28 21:52:44 +00:00
|
|
|
graceful = true
|
2025-06-28 17:07:53 +00:00
|
|
|
}
|
|
|
|
|
// Change of variable to make it more readable
|
|
|
|
|
const forceful = !graceful
|
|
|
|
|
|
2025-06-28 21:52:44 +00:00
|
|
|
SSLSnifferApp.db.close(forceful)
|
2025-06-28 17:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|