mirror of
https://github.com/hpware/news-analyze.git
synced 2025-07-17 16:09:06 +00:00
Update stuff.
Some checks are pending
Build and Push Beta Image / build-and-push (push) Waiting to run
Some checks are pending
Build and Push Beta Image / build-and-push (push) Waiting to run
This commit is contained in:
parent
c81767b903
commit
ea58cf5208
6 changed files with 46 additions and 30 deletions
|
@ -1,6 +1,7 @@
|
|||
import { Groq } from "groq-sdk";
|
||||
import sql from "~/server/components/postgres";
|
||||
import { checkIfUserHasCustomGroqKey } from "~/server/components/customgroqsystem";
|
||||
import getEnvFromDB from "~/server/components/getEnvFromDB";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const host = getRequestHost(event);
|
||||
|
@ -16,8 +17,9 @@ export default defineEventHandler(async (event) => {
|
|||
apiKey: doesTheUserHasACustomGroqApiAndWhatIsIt.customApi,
|
||||
});
|
||||
} else {
|
||||
const groq_api_key = await getEnvFromDB("groq_api_key");
|
||||
groqClient = new Groq({
|
||||
apiKey: process.env.NUXT_GROQ_API_KEY,
|
||||
apiKey: groq_api_key,
|
||||
});
|
||||
}
|
||||
const query = getQuery(event);
|
||||
|
|
|
@ -60,6 +60,12 @@ export default defineEventHandler(async (event) => {
|
|||
)
|
||||
`;
|
||||
|
||||
const createGlobalVars = await sql`
|
||||
CREATE TABLE IF NOT EXISTS global_vars (
|
||||
NAME TEXT PRIMARY KEY NOT NULL,
|
||||
VAR TEXT NOT NULL
|
||||
)
|
||||
`;
|
||||
return {
|
||||
createUsers: createUsers,
|
||||
usersList: usersList,
|
||||
|
@ -67,5 +73,6 @@ export default defineEventHandler(async (event) => {
|
|||
createSources: createSources,
|
||||
createUserOtherData: createUserOtherData,
|
||||
createArticlesArchive: createArticlesArchive,
|
||||
createGlobalVars: createGlobalVars,
|
||||
};
|
||||
});
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import argon2 from "argon2";
|
||||
import getEnvFromDB from "~/server/components/getEnvFromDB";
|
||||
|
||||
const defaultAvatarUrl = "https://s3.yhw.tw/news-analyze/avatar/default.png";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const salt = process.env.PASSWORD_HASH_SALT;
|
||||
if (!salt) {
|
||||
return {
|
||||
error: "SALT_NOT_FOUND",
|
||||
};
|
||||
}
|
||||
const body = await readBody(event);
|
||||
const { username, password } = body;
|
||||
console.log(password);
|
||||
|
@ -33,6 +28,7 @@ export default defineEventHandler(async (event) => {
|
|||
where username = ${username}`;
|
||||
console.log(fetchUserInfo[0]);
|
||||
if (fetchUserInfo.length === 0) {
|
||||
const salt = await getEnvFromDB("password_hash_salt");
|
||||
const hashedPassword = await argon2.hash(salt + password);
|
||||
const userUUID = uuidv4();
|
||||
const createNewUser = await sql`
|
||||
|
|
16
server/components/getEnvFromDB.ts
Normal file
16
server/components/getEnvFromDB.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
interface variReturn {
|
||||
name: string;
|
||||
var: string;
|
||||
}
|
||||
export default async function (vari: string) {
|
||||
const fetchVar = await sql<variReturn[]>`
|
||||
SELECT * FROM global_vars
|
||||
WHERE NAME = ${vari}`;
|
||||
if (fetchVar.length === 0) {
|
||||
throw new Error(
|
||||
"Cannot find var in the database. Have you followed this? https://github.com/hpware/news-analyze?tab=readme-ov-file#notes",
|
||||
);
|
||||
}
|
||||
return fetchVar[0].var;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue