- Translate all ~430 prompts to Spanish with cultural adaptations - Translate all UI strings (frontend, admin, history, broadcast) - Translate AI system prompts; models now respond in Spanish - Replace Twitch/Fossabot viewer voting with in-site vote buttons - Add POST /api/vote endpoint (IP-based, supports vote switching) - Vote buttons appear during voting phase with active state highlight - Rename project to argument.es throughout (package.json, cookie, DB) - Add docker-compose.yml with SQLite volume mount - Add .env.sample documenting all required and optional vars Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
import type { RoundState } from "./game.ts";
|
|
|
|
const dbPath = process.env.DATABASE_PATH ?? "argumentes.sqlite";
|
|
export const db = new Database(dbPath, { create: true });
|
|
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS rounds (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
num INTEGER,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
data TEXT
|
|
);
|
|
`);
|
|
|
|
export function saveRound(round: RoundState) {
|
|
const insert = db.prepare("INSERT INTO rounds (num, data) VALUES ($num, $data)");
|
|
insert.run({ $num: round.num, $data: JSON.stringify(round) });
|
|
}
|
|
|
|
export function getRounds(page: number = 1, limit: number = 10) {
|
|
const offset = (page - 1) * limit;
|
|
const countQuery = db.query("SELECT COUNT(*) as count FROM rounds").get() as { count: number };
|
|
const rows = db.query("SELECT data FROM rounds ORDER BY num DESC, id DESC LIMIT $limit OFFSET $offset")
|
|
.all({ $limit: limit, $offset: offset }) as { data: string }[];
|
|
return {
|
|
rounds: rows.map(r => JSON.parse(r.data) as RoundState),
|
|
total: countQuery.count,
|
|
page,
|
|
limit,
|
|
totalPages: Math.ceil(countQuery.count / limit)
|
|
};
|
|
}
|
|
|
|
export function getAllRounds() {
|
|
const rows = db.query("SELECT data FROM rounds ORDER BY num ASC, id ASC").all() as { data: string }[];
|
|
return rows.map(r => JSON.parse(r.data) as RoundState);
|
|
}
|
|
|
|
export function clearAllRounds() {
|
|
db.exec("DELETE FROM rounds;");
|
|
db.exec("DELETE FROM sqlite_sequence WHERE name = 'rounds';");
|
|
}
|