From d28967d3ae5ceb5f08d5dc6f80fe39e64af63306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Mon, 9 Jun 2025 10:46:34 +0800 Subject: [PATCH] =?UTF-8?q?Add=20bascic=20groq=20api=20key=20saving=20func?= =?UTF-8?q?tion=20(but=20I=20can't=20test=20it,=20as=20my=20laptop=20is=20?= =?UTF-8?q?basic=20unusable=20when=20launching=20the=20dev=20server,=20So?= =?UTF-8?q?=20I=20guess=20I'm=20testing=20in=20prod=20now=20=F0=9F=A4=B7?= =?UTF-8?q?=F0=9F=A4=B7=F0=9F=A4=B7=F0=9F=A4=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/app/windows/settings.vue | 1 + server/api/user/sendUserChanges.post.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/components/app/windows/settings.vue b/components/app/windows/settings.vue index 9301b93..c87f542 100644 --- a/components/app/windows/settings.vue +++ b/components/app/windows/settings.vue @@ -112,6 +112,7 @@ const submitChangeAction = async (action: string) => { body: JSON.stringify({ action: actionMatch.name, value: actionMatch.sendValue, + jsonValue: "", }), }); diff --git a/server/api/user/sendUserChanges.post.ts b/server/api/user/sendUserChanges.post.ts index 181e13e..f3b96fb 100644 --- a/server/api/user/sendUserChanges.post.ts +++ b/server/api/user/sendUserChanges.post.ts @@ -24,6 +24,30 @@ export default defineEventHandler(async (event) => { if (body.value.match()) { allowed = false; } + // Use Static values for now. + const requestChange = "groq_api_key"; + const apiKeyqq = body.value.match(clearBadDataRegex); + const allowedColumns = ["groq_api_key", "another_column_name"]; + + if (!allowedColumns.includes(requestChange)) { + throw new Error("Invalid column name provided"); + } + const sqlC = await sql.unsafe` + UPDATE user_other_data SET ${requestChange} = ${apiKeyqq[0]} + WHERE username = ${checkUserToken[0].username}`; + + /** + * // Example of how requestChange might be validated + const allowedColumns = ['groq_api_key', 'another_column_name']; + + if (!allowedColumns.includes(requestChange)) { + throw new Error('Invalid column name provided'); + } + + const sqlC = await sql` + UPDATE user_other_data SET ${sql.identifier([requestChange])} = ${apiKeyqq[0]} + WHERE username = ${checkUserToken[0].username}`; + */ return { body: body, allowed: allowed,