mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
Groq action actully works?
This commit is contained in:
parent
731d4d9a8c
commit
d99031b3b6
2 changed files with 54 additions and 5 deletions
36
server/api/user/submitGroqKey.ts
Normal file
36
server/api/user/submitGroqKey.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
export default defineEventHandler(async (event) => {
|
||||
// Check user data.
|
||||
const userToken = getCookie(event, "token");
|
||||
if (!userToken) {
|
||||
return {
|
||||
error: "ERR_NOT_ALLOWED",
|
||||
};
|
||||
}
|
||||
const checkUserToken = await sql`
|
||||
select * from usertokens
|
||||
where token=${userToken}
|
||||
`;
|
||||
if (checkUserToken.length === 0) {
|
||||
return {
|
||||
error: "ERR_NOT_ALLOWED",
|
||||
};
|
||||
}
|
||||
// Actual function
|
||||
const body = await readBody(event);
|
||||
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
|
||||
const requestChange = "groq_api_key";
|
||||
const apiKeyqq = body.value.match(clearBadDataRegex);
|
||||
|
||||
const sqlC = await sql.unsafe(
|
||||
`
|
||||
UPDATE user_other_data SET ${requestChange} = $1
|
||||
WHERE username = $2`,
|
||||
[apiKeyqq[0], checkUserToken[0].username],
|
||||
);
|
||||
return {
|
||||
body: body,
|
||||
data: body.value.match(clearBadDataRegex),
|
||||
sqlC: sqlC,
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue