refactor: update muxer-queue to use database adapter

- Replace direct better-sqlite3 imports with DatabaseAdapter pattern
- Make all muxer-queue functions async to support both SQLite and PostgreSQL
- Update database initialization to use adapter's getDatabase()
- Export DatabaseAdapter as SqliteDatabase for backward compatibility
- Update index.ts to handle async database initialization
- Update webserver.ts to await async database operations
- All functions now work with both SQLite and PostgreSQL backends
- Tests pass, no TypeScript errors
This commit is contained in:
MythEclipse
2026-05-14 14:55:21 +07:00
parent 84e20ae373
commit 94a3acf12e
4 changed files with 114 additions and 91 deletions
+10 -4
View File
@@ -40,7 +40,11 @@ const defaultSharedUIState: SharedUIState = {
isStreaming: false,
};
const sharedUIState: SharedUIState = getPersistedValue("web-ui-state", defaultSharedUIState);
let sharedUIState: SharedUIState = { ...defaultSharedUIState };
async function initializeSharedUIState() {
sharedUIState = await getPersistedValue("web-ui-state", defaultSharedUIState);
}
function getSharedUIState(): SharedUIState {
return { ...sharedUIState };
@@ -105,11 +109,13 @@ function rmsDb(pcm: Buffer): number {
return 20 * Math.log10(Math.max(rms, 1e-10));
}
export function startWebserver(
export async function startWebserver(
port: number = 3000,
_client: Client,
voiceController: VoiceController,
) {
await initializeSharedUIState();
const app = express();
const server = http.createServer(app);
@@ -243,7 +249,7 @@ export function startWebserver(
// Moderation API endpoints
app.get("/api/messages", async (req, res, next) => {
try {
const db = getDatabase();
const db = await getDatabase();
const { channel, type, limit = "50", offset = "0" } = req.query as {
channel?: string;
type?: string;
@@ -293,7 +299,7 @@ export function startWebserver(
);
}
const count = await syncSelectedChannelBacklog(_client, getDatabase(), guildId, channelId);
const count = await syncSelectedChannelBacklog(_client, await getDatabase(), guildId, channelId);
res.json({
success: true,
channelId,