mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
no comment still working on it
This commit is contained in:
1 parent
cea0014e18
commit
e11fca151c
87 files changed
+5710
-10182
No files matched your search
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file DatabaseManager.mjs — DatabaseManager — SQLite database manager for the web dashboard's persistent storage
|
||||
* @module src.dashboard.DatabaseManager
|
||||
* @module dashboard/DatabaseManager
|
||||
* @description MySQL connection pool wrapper for the dashboard. Provides parameterised
|
||||
* query execution and bcrypt hashing utilities for login code management.
|
||||
*/
|
||||
|
||||
import { compare, genSalt, hash } from "bcryptjs";
|
||||
@@ -8,12 +9,14 @@ import { createPool } from "mysql2/promise";
|
||||
import { logger } from "../constants/Logger.mjs";
|
||||
|
||||
/**
|
||||
* DatabaseManager — MySQL pool for dashboard login codes and API tokens.
|
||||
* Adapted for use with the Fluxer bot.
|
||||
* @class
|
||||
* @description Wraps a mysql2 connection pool with convenience methods for
|
||||
* parameterised queries and bcrypt hash operations.
|
||||
*/
|
||||
export class DatabaseManager {
|
||||
/**
|
||||
* @param {import("mysql2/promise").PoolOptions} config
|
||||
* Create a new DatabaseManager.
|
||||
* @param {object} config - mysql2 pool configuration (host, user, password, database, etc.).
|
||||
*/
|
||||
constructor(config) {
|
||||
this.db = createPool({
|
||||
@@ -26,19 +29,21 @@ export class DatabaseManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a raw SQL query.
|
||||
* @param {string} query
|
||||
* @returns {Promise<[import("mysql2/promise").QueryResult, import("mysql2/promise").FieldPacket[]]>}
|
||||
* Execute a raw SQL query (no parameter binding).
|
||||
* @async
|
||||
* @param {string} query - The SQL query string.
|
||||
* @returns {Promise<Array>} The query result rows and fields.
|
||||
*/
|
||||
async query(query) {
|
||||
return this.db.query(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a parameterized SQL query.
|
||||
* @param {string} query
|
||||
* @param {any[]} [data]
|
||||
* @returns {Promise<import("mysql2/promise").QueryResult>}
|
||||
* Execute a parameterised SQL query.
|
||||
* @async
|
||||
* @param {string} query - The SQL query with `?` placeholders.
|
||||
* @param {Array} data - The values to bind.
|
||||
* @returns {Promise<Array>} The result rows.
|
||||
*/
|
||||
async execute(query, data) {
|
||||
const [res, _fields] = await this.db.execute(query, data);
|
||||
@@ -46,9 +51,10 @@ export class DatabaseManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a plaintext string using bcrypt.
|
||||
* @param {string} plain
|
||||
* @returns {Promise<string>}
|
||||
* Generate a bcrypt hash of the given plaintext.
|
||||
* @async
|
||||
* @param {string} plain - The plaintext string.
|
||||
* @returns {Promise<string>} The hashed string.
|
||||
*/
|
||||
async hash(plain) {
|
||||
const salt = await genSalt(10);
|
||||
@@ -57,16 +63,17 @@ export class DatabaseManager {
|
||||
|
||||
/**
|
||||
* Compare a plaintext string against a bcrypt hash.
|
||||
* @param {string} plain
|
||||
* @param {string} hashed
|
||||
* @returns {Promise<boolean>}
|
||||
* @async
|
||||
* @param {string} plain - The plaintext string.
|
||||
* @param {string} hashed - The bcrypt hash.
|
||||
* @returns {Promise<boolean>} True if the plaintext matches the hash.
|
||||
*/
|
||||
async compareHash(plain, hashed) {
|
||||
return await compare(plain, hashed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gracefully close the connection pool.
|
||||
* Close the underlying MySQL connection pool.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
close() {
|
||||
|
||||
Reference in new issue
Block a user