This commit is contained in:
2025-06-08 23:33:26 +09:00
parent 99c5aa8ee0
commit be9ff546a4

View File

@ -141,16 +141,6 @@ function initializeDatabase(): Database {
// Initialize settings table with default values
initializeSettings(db);
// ALTER
// ALTER TABLE feeds ADD COLUMN category TEXT DEFAULT NULL;
// Ensure the category column exists in feeds
const feedInfos = db.prepare("PRAGMA table_info(feeds);").all();
const hasFeedCategory = feedInfos.some((col: any) => col.name === "category");
if (!hasFeedCategory) {
db.exec("ALTER TABLE feeds ADD COLUMN category TEXT DEFAULT NULL;");
}
// Ensure the category column exists in episodes
const episodeInfos = db.prepare("PRAGMA table_info(episodes);").all();
const hasEpisodeCategory = episodeInfos.some(
@ -1623,7 +1613,7 @@ export async function initializeSettings(database: Database): Promise<void> {
required: true,
},
{
key: "OPENAI_API_ENDPOINT",
key: "OPENAI_API_ENDPOINT",
value: null,
isCredential: false,
description: "OpenAI API Endpoint URL",
@ -1765,7 +1755,7 @@ export async function initializeSettings(database: Database): Promise<void> {
for (const setting of defaultSettings) {
try {
const stmt = database.prepare(
"INSERT OR IGNORE INTO settings (key, value, is_credential, description, default_value, required, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)"
"INSERT OR IGNORE INTO settings (key, value, is_credential, description, default_value, required, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
);
stmt.run(
setting.key,
@ -1774,7 +1764,7 @@ export async function initializeSettings(database: Database): Promise<void> {
setting.description,
setting.defaultValue,
setting.required ? 1 : 0,
now
now,
);
} catch (error) {
console.error(`Error initializing setting ${setting.key}:`, error);
@ -1823,11 +1813,14 @@ export async function getSetting(key: string): Promise<Setting | null> {
}
}
export async function updateSetting(key: string, value: string): Promise<boolean> {
export async function updateSetting(
key: string,
value: string,
): Promise<boolean> {
try {
const now = new Date().toISOString();
const stmt = db.prepare(
"UPDATE settings SET value = ?, updated_at = ? WHERE key = ?"
"UPDATE settings SET value = ?, updated_at = ? WHERE key = ?",
);
const result = stmt.run(value, now, key);
return result.changes > 0;