From 2915123f71ef69be7a6f22d9923ed09221bedb24 Mon Sep 17 00:00:00 2001 From: Omer Sabic Date: Thu, 30 May 2024 09:17:59 +0200 Subject: [PATCH] updated env vars --- .env.example | 7 ++++++- src/db/schemas.js | 20 ++++++++++---------- src/index.js | 4 ++-- src/utils/ai.js | 3 ++- src/utils/env.js | 3 +++ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index 06bc66f..5ef5f3a 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,9 @@ PORT=8080 HOST=127.0.0.1 PUBLIC_API_URL=http://localhost:3000 FRONTEND_URL=http://localhost:3002 -SITES_HOST=http://localhost:3001 \ No newline at end of file +SITES_HOST=http://localhost:3001 + +GOOGLE_CLIENT_ID= +GOOGLE_SECRET= + +OPENAI_TOKEN= \ No newline at end of file diff --git a/src/db/schemas.js b/src/db/schemas.js index e21d6eb..7c03ef5 100644 --- a/src/db/schemas.js +++ b/src/db/schemas.js @@ -24,7 +24,7 @@ export const sessions = pgTable("sessions", { function makeid(length) { let result = ''; - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const characters = 'abcdefghijklmnopqrstuvwxyz'; const charactersLength = characters.length; let counter = 0; while (counter < length) { @@ -41,16 +41,16 @@ export const sites = pgTable("sites", { primary_color_hex: varchar("primary_color_hex", { length: 6 }).default("c4ced4").notNull(), secondary_color_hex: varchar("secondary_color_hex", { length: 6 }).default('27251f').notNull(), text_color_hex: varchar("text_color_hex", { length: 6 }).default('ffffff').notNull(), - title: text("title"), - subtitle: text("subtitle"), - domain: text("domain").unique(), - use_freebie: boolean("send_freebie"), - freebie_name: text("freebie_name"), - freebie_url: text("freebie_url"), - freebie_text: text("freebie_text"), - freebie_image_url: text("freebie_image_url"), + title: text("title").default("The best blog in the world!"), + subtitle: text("subtitle").default("Some extra info about the best blog in the world!"), + domain: text("domain").default("").unique(), + use_freebie: boolean("send_freebie").default(""), + freebie_name: text("freebie_name").default(""), + freebie_url: text("freebie_url").default(""), + freebie_text: text("freebie_text").default(""), + freebie_image_url: text("freebie_image_url").default(""), subdomain_slug: text("subdomain_slug").$defaultFn(() => { - return makeid(7); + return makeid(10); }), social_medias: jsonb("social_medias") }); diff --git a/src/index.js b/src/index.js index fd9b73d..91f4620 100644 --- a/src/index.js +++ b/src/index.js @@ -40,8 +40,8 @@ export const main = async () => { scope: ['https://www.googleapis.com/auth/youtube.readonly', 'https://www.googleapis.com/auth/youtube.force-ssl', "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"], credentials: { client: { - id: '103003963446-6m80lqbe4bkgjv1nq5ihmju0bb6agkkg.apps.googleusercontent.com', - secret: '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' + id: env.GOOGLE_CLIENT_ID, + secret: env.GOOGLE_SECRET }, auth: oauth.GOOGLE_CONFIGURATION }, diff --git a/src/utils/ai.js b/src/utils/ai.js index 118a637..a374b3e 100644 --- a/src/utils/ai.js +++ b/src/utils/ai.js @@ -1,5 +1,6 @@ const defaultModel = '@hf/mistralai/mistral-7b-instruct-v0.2'; import OpenAI from "openai"; +import { env } from "./env"; const openai = new OpenAI({ apiKey: "", @@ -28,7 +29,7 @@ async function promptGPT(prompt, { model, is_json } = {model: "gpt-3.5-turbo", i const options = { method: 'POST', - headers: { Authorization: 'Bearer sk-proj-kngnyz8wyoxx4Sw4X4OHT3BlbkFJJBmYAE9odHtYPu1OBEG7', "Content-Type": "application/json" }, + headers: { Authorization: `Bearer ${env.OPENAI_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify({ "model": "gpt-3.5-turbo", // "max_tokens": max_tokens, diff --git a/src/utils/env.js b/src/utils/env.js index d292f86..4256f54 100644 --- a/src/utils/env.js +++ b/src/utils/env.js @@ -9,6 +9,9 @@ const envSchema = z.object({ PUBLIC_API_URL: z.string(), FRONTEND_URL: z.string(), SITES_HOST: z.string(), + GOOGLE_CLIENT_ID: z.string(), + GOOGLE_SECRET: z.string(), + OPENAI_TOKEN: z.string() }); export const env = envSchema.parse(process.env);