mirror of
https://github.com/hpware/news-analyze.git
synced 2025-07-16 15:39: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
22
.env.example
22
.env.example
|
@ -1,28 +1,12 @@
|
||||||
# Please use .env.exmaple as an starting point. Rename it to .env and fill in the values, the application requrires it.
|
# Please use .env.exmaple as an starting point. Rename it to .env and fill in the values, the application requrires it.
|
||||||
|
|
||||||
# This is the default .env file.
|
# This is the default .env file.
|
||||||
|
|
||||||
# S3 INFO
|
|
||||||
S3_ACCESS_KEY=""
|
|
||||||
S3_SECRET_KEY=""
|
|
||||||
S3_BUCKETNAME=""
|
|
||||||
S3_ENDPOINT=""
|
|
||||||
|
|
||||||
# GITHUB OAUTH (NOT WORKING 4n)
|
|
||||||
NUXT_GITHUB_CLIENT_ID=""
|
|
||||||
NUXT_GITHUB_CLIENT_SECRET=""
|
|
||||||
|
|
||||||
# GLOBAL DATABASE
|
# GLOBAL DATABASE
|
||||||
POSTGRES_URL=""
|
POSTGRES_URL=""
|
||||||
|
|
||||||
|
# THE BELOW TWO IS NOW IN THE DB, PLEASE FOLOW THIS GUIDE: https://github.com/hpware/news-analyze?tab=readme-ov-file#notes
|
||||||
# GROQ API KEY
|
# GROQ API KEY
|
||||||
GROQ_API_KEY=""
|
#GROQ_API_KEY=""
|
||||||
|
|
||||||
# PASSWORD SALT
|
# PASSWORD SALT
|
||||||
PASSWORD_HASH_SALT=""
|
#PASSWORD_HASH_SALT=""
|
||||||
|
|
||||||
# CF TURNSTILE
|
|
||||||
NUXT_CF_TURNSTILE_SITE_KEY=""
|
|
||||||
NUXT_CF_TURNSTILE_SECRET_KEY=""
|
|
||||||
|
|
||||||
NUXT_DEV_ENV=false
|
|
||||||
|
|
19
README.md
19
README.md
|
@ -25,6 +25,20 @@ Beta (Beta Docker Image): https://newsbeta.20090526.xyz
|
||||||
|
|
||||||
https://github.com/user-attachments/assets/29414c5d-3b2f-420d-93c0-95c14a15bbb7
|
https://github.com/user-attachments/assets/29414c5d-3b2f-420d-93c0-95c14a15bbb7
|
||||||
|
|
||||||
|
## Notes:
|
||||||
|
The enviroment vars are stored in the database, which is cursed, I know, but this is the only way to let the system access new envs sent by the user, so if you are trying to spin up a instence of this app you MUST put the postgres url in the .env & create a table using beekeeper studio (my choice for SQL editing, you can choose whatever you like), and after that you can create the entire database by using this api call, https://<<your_domain>>/api/create_database in your browser.
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS global_vars (
|
||||||
|
NAME TEXT PRIMARY KEY NOT NULL,
|
||||||
|
VAR TEXT NOT NULL
|
||||||
|
);
|
||||||
|
INSERT INTO global_vars(name, var)
|
||||||
|
VALUES ('groq_api_key', '<<YOUR_API_KEY_HERE>>');
|
||||||
|
INSERT INTO global_vars(name, var)
|
||||||
|
VALUES ('password_hash_salt', '<<YOUR_PASSWORD_SALT_HERE>>');
|
||||||
|
```
|
||||||
|
Replace `<<YOUR_API_KEY_HERE>>` with your actual api key, and also replace `<<YOUR_PASSWORD_SALT_HERE>>` with a random salt you get by running this command on your Mac/Linux device (Windows idk) `openssl rand -base64 48`.
|
||||||
|
|
||||||
## Issues:
|
## Issues:
|
||||||
### Onboarding:
|
### Onboarding:
|
||||||
Onboarding is a must for most people that are using the app for the first time, but I want to do to via a non-video like system, however implementing the function in a already large repo is kinda hard. So later this week, I will just add a basic video onboarding system.
|
Onboarding is a must for most people that are using the app for the first time, but I want to do to via a non-video like system, however implementing the function in a already large repo is kinda hard. So later this week, I will just add a basic video onboarding system.
|
||||||
|
@ -59,13 +73,10 @@ This code is absolutly NOT designed to be spinned up at Vercel or Netlify, it ha
|
||||||
### The API returning outdated data from more than 5+ years:
|
### The API returning outdated data from more than 5+ years:
|
||||||
Here is the GitHub Issue: https://github.com/hpware/news-analyze/issues/2
|
Here is the GitHub Issue: https://github.com/hpware/news-analyze/issues/2
|
||||||
|
|
||||||
### Groq API not loading to .env for some reasons.
|
|
||||||
If the user did not load a GROQ api, the summerizing system will just fail outright. Fixing this rn.
|
|
||||||
|
|
||||||
### When using the desktop in the dev env it pops up an error
|
### When using the desktop in the dev env it pops up an error
|
||||||

|

|
||||||
|
|
||||||
For some reasons, Nuxt's dev env prev does not display this error, but with the newer ones, it started displaying this error, please run `./wipedev.sh` or `./wipedev.bat` and restart the dev server. (And this is only a temp fix, I have no idea how can I fix this, if you have a fix, please submit a PR thx.)
|
For some reasons, Nuxt's dev env prev does not display this error, but with the newer ones, it started displaying this error, please run `./wipedev.sh` or `./wipedev.bat` and restart the dev server. (And this is only a temp fix, I have no idea how can I fix this, if you have a fix, please submit a PR, thx.)
|
||||||
|
|
||||||
## Why?
|
## Why?
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Groq } from "groq-sdk";
|
import { Groq } from "groq-sdk";
|
||||||
import sql from "~/server/components/postgres";
|
import sql from "~/server/components/postgres";
|
||||||
import { checkIfUserHasCustomGroqKey } from "~/server/components/customgroqsystem";
|
import { checkIfUserHasCustomGroqKey } from "~/server/components/customgroqsystem";
|
||||||
|
import getEnvFromDB from "~/server/components/getEnvFromDB";
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const host = getRequestHost(event);
|
const host = getRequestHost(event);
|
||||||
|
@ -16,8 +17,9 @@ export default defineEventHandler(async (event) => {
|
||||||
apiKey: doesTheUserHasACustomGroqApiAndWhatIsIt.customApi,
|
apiKey: doesTheUserHasACustomGroqApiAndWhatIsIt.customApi,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const groq_api_key = await getEnvFromDB("groq_api_key");
|
||||||
groqClient = new Groq({
|
groqClient = new Groq({
|
||||||
apiKey: process.env.NUXT_GROQ_API_KEY,
|
apiKey: groq_api_key,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const query = getQuery(event);
|
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 {
|
return {
|
||||||
createUsers: createUsers,
|
createUsers: createUsers,
|
||||||
usersList: usersList,
|
usersList: usersList,
|
||||||
|
@ -67,5 +73,6 @@ export default defineEventHandler(async (event) => {
|
||||||
createSources: createSources,
|
createSources: createSources,
|
||||||
createUserOtherData: createUserOtherData,
|
createUserOtherData: createUserOtherData,
|
||||||
createArticlesArchive: createArticlesArchive,
|
createArticlesArchive: createArticlesArchive,
|
||||||
|
createGlobalVars: createGlobalVars,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
import sql from "~/server/components/postgres";
|
import sql from "~/server/components/postgres";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import argon2 from "argon2";
|
import argon2 from "argon2";
|
||||||
|
import getEnvFromDB from "~/server/components/getEnvFromDB";
|
||||||
|
|
||||||
const defaultAvatarUrl = "https://s3.yhw.tw/news-analyze/avatar/default.png";
|
const defaultAvatarUrl = "https://s3.yhw.tw/news-analyze/avatar/default.png";
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
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 body = await readBody(event);
|
||||||
const { username, password } = body;
|
const { username, password } = body;
|
||||||
console.log(password);
|
console.log(password);
|
||||||
|
@ -33,6 +28,7 @@ export default defineEventHandler(async (event) => {
|
||||||
where username = ${username}`;
|
where username = ${username}`;
|
||||||
console.log(fetchUserInfo[0]);
|
console.log(fetchUserInfo[0]);
|
||||||
if (fetchUserInfo.length === 0) {
|
if (fetchUserInfo.length === 0) {
|
||||||
|
const salt = await getEnvFromDB("password_hash_salt");
|
||||||
const hashedPassword = await argon2.hash(salt + password);
|
const hashedPassword = await argon2.hash(salt + password);
|
||||||
const userUUID = uuidv4();
|
const userUUID = uuidv4();
|
||||||
const createNewUser = await sql`
|
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