Initial Commit
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s

This commit is contained in:
2026-08-28 22:55:32 +10:00
parent d8d4ecbe8a
commit f00405ed24
16 changed files with 1008 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import dotenv from 'dotenv';
import path from 'path';
import pg from 'pg';
dotenv.config({ path: path.resolve(__dirname, '../.env') });
export function getDbClient() {
return new pg.Client({
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT) || 5432,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
});
}
export async function getStorageState() {
const client = getDbClient();
await client.connect();
try {
const { rows } = await client.query(
`SELECT value FROM settings WHERE key = $1 LIMIT 1`,
['session']
);
if (!rows.length) throw new Error("No 'session' row found in settings table");
const { value } = rows[0];
return typeof value === 'string' ? JSON.parse(value) : value;
} finally {
await client.end();
}
}