fix: address Phase 1 review — union types, auto playedAt, ESM imports, gitignore config.json

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Opus 4.6 committed 2026-03-30 00:26:55 +08:00
1 parent 9931d8b40d
commit bc89c553b7
5 files changed
+15 -14

No files matched your search

+1
View File
@@ -3,4 +3,5 @@ dist/
/data/
*.db
.env
config.json
.superpowers/
+1 -2
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, afterEach } from "vitest";
import { join } from "node:path";
import { mkdtempSync, rmSync } from "node:fs";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { getDefaultConfig, loadConfig, saveConfig } from "./config.js";
@@ -41,7 +41,6 @@ describe("config", () => {
// Save a partial config by writing only some fields
const partial = { webPort: 8080, locale: "en" };
const { writeFileSync } = require("node:fs");
writeFileSync(path, JSON.stringify(partial), "utf-8");
const loaded = loadConfig(path);
+2 -2
View File
@@ -3,8 +3,8 @@ import { dirname } from "node:path";
export interface BotConfig {
webPort: number;
locale: string;
theme: string;
locale: "zh" | "en";
theme: "dark" | "light";
commandPrefix: string;
commandAliases: Record<string, string>;
neteaseApiPort: number;
+1 -3
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { createDatabase, type BotDatabase, type BotInstance } from "./database.js";
import { createDatabase, type BotDatabase, type BotInstance, type PlayHistoryEntry } from "./database.js";
describe("database", () => {
let botDb: BotDatabase;
@@ -32,7 +32,6 @@ describe("database", () => {
album: "Test Album",
platform: "netease",
coverUrl: "https://example.com/cover.jpg",
playedAt: new Date().toISOString(),
});
botDb.addPlayHistory({
@@ -43,7 +42,6 @@ describe("database", () => {
album: "Another Album",
platform: "qq",
coverUrl: "https://example.com/cover2.jpg",
playedAt: new Date().toISOString(),
});
const history = botDb.getPlayHistory("bot1", 10);
+10 -7
View File
@@ -1,14 +1,17 @@
import Database from "better-sqlite3";
export interface PlayHistoryRecord {
id?: number;
export interface PlayHistoryEntry {
botId: string;
songId: string;
songName: string;
artist: string;
album: string;
platform: string;
platform: "netease" | "qq";
coverUrl: string;
}
export interface PlayHistoryRecord extends PlayHistoryEntry {
id: number;
playedAt: string;
}
@@ -25,7 +28,7 @@ export interface BotInstance {
export interface BotDatabase {
db: Database.Database;
addPlayHistory(record: Omit<PlayHistoryRecord, "id">): void;
addPlayHistory(entry: PlayHistoryEntry): void;
getPlayHistory(botId: string, limit: number): PlayHistoryRecord[];
saveBotInstance(instance: BotInstance): void;
getBotInstances(): BotInstance[];
@@ -44,7 +47,7 @@ function initTables(db: Database.Database): void {
album TEXT NOT NULL,
platform TEXT NOT NULL,
coverUrl TEXT NOT NULL,
playedAt TEXT NOT NULL
playedAt TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS bot_instances (
@@ -66,8 +69,8 @@ export function createDatabase(dbPath: string): BotDatabase {
initTables(db);
const insertHistory = db.prepare(`
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl, playedAt)
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl, @playedAt)
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl)
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl)
`);
const selectHistory = db.prepare(`