This commit is contained in:
Adrien Bouvais 2024-06-01 19:05:54 +02:00
parent 05f302465e
commit 7f74ddef2e
7 changed files with 6 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os"
"github.com/edgedb/edgedb-go" "github.com/edgedb/edgedb-go"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -30,9 +31,6 @@ type TokenResponse struct {
ProviderToken string `json:"provider_token"` ProviderToken string `json:"provider_token"`
} }
// TODO add to env
const EDGEDB_AUTH_BASE_URL = "https://jade-hackathon--mrbounty.c-40.i.aws.edgedb.cloud/db/main/ext/auth"
func getGoogleUserProfile(providerToken string) (string, string, string) { func getGoogleUserProfile(providerToken string) (string, string, string) {
// Fetch the discovery document // Fetch the discovery document
resp, err := http.Get("https://accounts.google.com/.well-known/openid-configuration") resp, err := http.Get("https://accounts.google.com/.well-known/openid-configuration")
@ -158,7 +156,7 @@ func handleUiSignIn(c *fiber.Ctx) error {
Secure: true, Secure: true,
}) })
return c.Redirect(fmt.Sprintf("%s/ui/signup?challenge=%s", EDGEDB_AUTH_BASE_URL, challenge), fiber.StatusTemporaryRedirect) return c.Redirect(fmt.Sprintf("%s/ui/signup?challenge=%s", os.Getenv("EDGEDB_AUTH_BASE_URL"), challenge), fiber.StatusTemporaryRedirect)
} }
func handleCallbackSignup(c *fiber.Ctx) error { func handleCallbackSignup(c *fiber.Ctx) error {
@ -174,7 +172,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
panic("Could not find 'verifier' in the cookie store. Is this the same user agent/browser that started the authorization flow?") panic("Could not find 'verifier' in the cookie store. Is this the same user agent/browser that started the authorization flow?")
} }
codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier) codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", os.Getenv("EDGEDB_AUTH_BASE_URL"), code, verifier)
resp, err := http.Get(codeExchangeURL) resp, err := http.Get(codeExchangeURL)
if err != nil { if err != nil {
fmt.Println("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")
@ -281,7 +279,7 @@ func handleCallback(c *fiber.Ctx) error {
panic("Could not find 'verifier' in the cookie store. Is this the same user agent/browser that started the authorization flow?") panic("Could not find 'verifier' in the cookie store. Is this the same user agent/browser that started the authorization flow?")
} }
codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier) codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", os.Getenv("EDGEDB_AUTH_BASE_URL"), code, verifier)
resp, err := http.Get(codeExchangeURL) resp, err := http.Get(codeExchangeURL)
if err != nil { if err != nil {
fmt.Println("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")

View File

@ -443,7 +443,6 @@ func generateLimitReachedChatHTML(c *fiber.Ctx) string {
clientSecretSession := CreateClientSecretSession(c) clientSecretSession := CreateClientSecretSession(c)
// TODO Replace by live API call
stripeTable := ` stripeTable := `
<stripe-pricing-table <stripe-pricing-table
pricing-table-id="prctbl_1PJAxDP2nW0okNQyY0Q3mbg4" pricing-table-id="prctbl_1PJAxDP2nW0okNQyY0Q3mbg4"

View File

@ -209,7 +209,6 @@ func Message2RequestMessage(messages []Message, context string) []RequestMessage
} }
func GetAvailableModels(c *fiber.Ctx) []ModelInfo { func GetAvailableModels(c *fiber.Ctx) []ModelInfo {
// TODO Filter if key is not available
var models []ModelInfo var models []ModelInfo
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Query(edgeCtx, ` err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Query(edgeCtx, `
SELECT ModelInfo { SELECT ModelInfo {

View File

@ -29,7 +29,6 @@ func generatePricingTableChatHTML(c *fiber.Ctx) string {
clientSecretSession := CreateClientSecretSession(c) clientSecretSession := CreateClientSecretSession(c)
// TODO Replace by live API call
stripeTable := ` stripeTable := `
<stripe-pricing-table <stripe-pricing-table
pricing-table-id="prctbl_1PJAxDP2nW0okNQyY0Q3mbg4" pricing-table-id="prctbl_1PJAxDP2nW0okNQyY0Q3mbg4"
@ -85,7 +84,6 @@ func CreateNewStripeCustomer(name string, email string) string {
} }
func IsCurrentUserSubscribed(c *fiber.Ctx) (bool, bool) { func IsCurrentUserSubscribed(c *fiber.Ctx) (bool, bool) {
// TODO Change to add both plan
var user User var user User
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user) err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user)
if err != nil { if err != nil {

View File

@ -166,11 +166,6 @@ func main() {
} }
} }
// The route to add keys, idk where to put it so it's here
// Deserve a good REDO lol
// I mean, look at this shit...
// 300 lines, I'm sure it can be done in 50
// TODO REDO and maybe find it a better place
func addKeys(c *fiber.Ctx) error { func addKeys(c *fiber.Ctx) error {
openaiKey := c.FormValue("openai_key") openaiKey := c.FormValue("openai_key")
anthropicKey := c.FormValue("anthropic_key") anthropicKey := c.FormValue("anthropic_key")

View File

@ -22,7 +22,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="column" id="content-column"> <div class="column" id="content-column" style="width: 100px;">
{% if not IsPlaceholder %} {% if not IsPlaceholder %}
<div class="{% if not notFlex%} is-flex {% endif %} is-align-items-start"> <div class="{% if not notFlex%} is-flex {% endif %} is-align-items-start">
<div class="message-content" style="width: 100%; overflow-y: hidden;" <div class="message-content" style="width: 100%; overflow-y: hidden;"

View File

@ -6,7 +6,7 @@
</figure> </figure>
</div> </div>
<div class="column" id="content-column"> <div class="column" id="content-column" style="width: 100px;">
<div class="is-flex is-align-items-start"> <div class="is-flex is-align-items-start">
<div class="message-content" style="width: 100%; overflow-y: hidden;"> <div class="message-content" style="width: 100%; overflow-y: hidden;">
<div class="message-header"> <div class="message-header">