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 17:19:40 +00:00
|
|
|
private __db: Database
|
2025-06-28 17:07:53 +00:00
|
|
|
|
|
|
|
|
// UGLY: should be more flexible
|
|
|
|
|
constructor() {
|
2025-06-28 17:19:40 +00:00
|
|
|
this.__db = SSLSnifferApp.initDatabase()
|
|
|
|
|
SSLSnifferApp.initialized = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public get db() {
|
|
|
|
|
return this.__db
|
2025-06-28 17:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This needs to be static as it doesn't need the object
|
|
|
|
|
private static initDatabase() {
|
|
|
|
|
|
|
|
|
|
const db = new Database(
|
|
|
|
|
DB_PATH,
|
|
|
|
|
{
|
|
|
|
|
create: true,
|
|
|
|
|
strict: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Improve performance
|
|
|
|
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
|
|
|
return db
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private closeDatabase(graceful?: boolean) {
|
|
|
|
|
if (!graceful) {
|
|
|
|
|
graceful = true
|
|
|
|
|
}
|
|
|
|
|
// Change of variable to make it more readable
|
|
|
|
|
const forceful = !graceful
|
|
|
|
|
|
|
|
|
|
this.db.close(forceful)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|