From 3720ccbff5db741c084f6bd85ea975562b0083f7 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Wed, 28 May 2025 11:38:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=BB=88=E7=AB=AF=E6=A0=B7=E5=BC=8F=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/terminal-theme.repository.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/repositories/terminal-theme.repository.ts b/packages/backend/src/repositories/terminal-theme.repository.ts index 9456211..7cbc62f 100644 --- a/packages/backend/src/repositories/terminal-theme.repository.ts +++ b/packages/backend/src/repositories/terminal-theme.repository.ts @@ -182,16 +182,37 @@ export const createTheme = async (themeDto: CreateTerminalThemeDto): Promise 是否成功更新 */ export const updateTheme = async (id: number, themeDto: UpdateTerminalThemeDto): Promise => { - const now = Date.now(); - const themeDataJson = JSON.stringify(themeDto.themeData); + const nowSeconds = Math.floor(Date.now() / 1000); + const theme = themeDto.themeData; + + const setClauses = [ + 'name = ?', + 'foreground = ?', 'background = ?', 'cursor = ?', 'cursor_accent = ?', + 'selection_background = ?', 'black = ?', 'red = ?', 'green = ?', 'yellow = ?', 'blue = ?', + 'magenta = ?', 'cyan = ?', 'white = ?', 'bright_black = ?', 'bright_red = ?', 'bright_green = ?', + 'bright_yellow = ?', 'bright_blue = ?', 'bright_magenta = ?', 'bright_cyan = ?', 'bright_white = ?', + 'updated_at = ?' + ]; + + const values = [ + themeDto.name, + theme?.foreground ?? null, theme?.background ?? null, theme?.cursor ?? null, theme?.cursorAccent ?? null, + theme?.selectionBackground ?? null, theme?.black ?? null, theme?.red ?? null, theme?.green ?? null, theme?.yellow ?? null, theme?.blue ?? null, + theme?.magenta ?? null, theme?.cyan ?? null, theme?.white ?? null, theme?.brightBlack ?? null, theme?.brightRed ?? null, theme?.brightGreen ?? null, + theme?.brightYellow ?? null, theme?.brightBlue ?? null, theme?.brightMagenta ?? null, theme?.brightCyan ?? null, theme?.brightWhite ?? null, + nowSeconds, + id // For WHERE clause + ]; + const sql = ` UPDATE terminal_themes - SET name = ?, theme_data = ?, updated_at = ? - WHERE id = ? AND is_preset = 0 + SET ${setClauses.join(', ')} + WHERE id = ? AND theme_type = 'user' `; + try { const db = await getDbInstance(); - const result = await runDb(db, sql, [themeDto.name, themeDataJson, now, id]); + const result = await runDb(db, sql, values); return result.changes > 0; } catch (err: any) { console.error(`更新 ID 为 ${id} 的终端主题失败:`, err.message);