-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Guru Form --------- Co-authored-by: aralyekta <[email protected]>
- Loading branch information
1 parent
acf92da
commit 648dfa5
Showing
19 changed files
with
653 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/gurubase-backend/backend/core/migrations/0058_gurucreationform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.2.18 on 2025-03-05 13:10 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0057_widgetid_is_wildcard'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GuruCreationForm', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('email', models.EmailField(max_length=254)), | ||
('github_repo', models.URLField(max_length=2000)), | ||
('docs_url', models.URLField(max_length=2000)), | ||
('use_case', models.TextField(blank=True, null=True)), | ||
('notified', models.BooleanField(default=False)), | ||
('date_created', models.DateTimeField(auto_now_add=True)), | ||
('date_updated', models.DateTimeField(auto_now=True)), | ||
], | ||
options={ | ||
'ordering': ['-date_created'], | ||
}, | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
src/gurubase-backend/backend/core/migrations/0059_gurucreationform_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2.18 on 2025-03-05 13:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0058_gurucreationform'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='gurucreationform', | ||
name='source', | ||
field=models.CharField(default='/', max_length=50), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from crawl4ai.markdown_generation_strategy import DefaultMarkdownGenerator | ||
logging.getLogger("openai").setLevel(logging.ERROR) | ||
logging.getLogger("httpx").setLevel(logging.ERROR) | ||
from core.exceptions import ThrottlingException | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -816,3 +817,35 @@ def get_proxies(self): | |
return [] | ||
|
||
return response.json() | ||
|
||
|
||
class MailgunRequester(): | ||
def __init__(self): | ||
self.base_url = "https://api.mailgun.net/v3" | ||
self.api_key = settings.MAILGUN_API_KEY | ||
|
||
def send_email(self, to, subject, body): | ||
data = { | ||
"from": "Anteon (formerly Ddosify) <[email protected]>", | ||
"to": to, | ||
"subject": subject, | ||
"text": body | ||
} | ||
try: | ||
email_response = requests.post(url="https://api.mailgun.net/v3/mail.getanteon.com/messages", | ||
auth=("api", self.api_key), | ||
data=data) | ||
|
||
if not email_response.ok: | ||
if email_response.status_code >= 400: | ||
raise ThrottlingException(f"Email send error: {email_response.text} - Status Code: {email_response.status_code}") | ||
raise Exception(f"Email send error: {email_response.text} - Status Code: {email_response.status_code}") | ||
|
||
logger.info(f"Email sent to: {to}. Subject: {subject}") | ||
except ThrottlingException as e: | ||
exception_code = "E-101" | ||
logger.fatal(f"Can not send email. Email: {to}. Subject: {subject} Code: {exception_code}") | ||
raise | ||
except Exception as e: | ||
exception_code = "E-100" | ||
logger.fatal(f"Can not send email. Email: {to}. Subject: {subject} Code: {exception_code}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use client"; | ||
|
||
import { useSearchParams } from "next/navigation"; | ||
import { submitGuruCreationForm, getCurrentUserEmail } from "@/app/actions"; | ||
import GuruForm from "@/components/GuruForm/GuruForm"; | ||
import HeaderFooterWrap from "@/components/GuruForm/HeaderFooterWrap"; | ||
import { redirect } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export default function UserInfoPage() { | ||
const searchParams = useSearchParams(); | ||
const source = searchParams.get("source") || "unknown"; | ||
const [userEmail, setUserEmail] = useState(null); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const isSelfHosted = process.env.NEXT_PUBLIC_NODE_ENV === "selfhosted"; | ||
|
||
useEffect(() => { | ||
const fetchUserEmail = async () => { | ||
try { | ||
const email = await getCurrentUserEmail(); | ||
setUserEmail(email); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
fetchUserEmail(); | ||
}, []); | ||
|
||
// Mock function to handle form submission | ||
const handleFormSubmit = async (data) => { | ||
try { | ||
const formData = new FormData(); | ||
formData.append("email", data.email); | ||
formData.append("github_repo", data.githubLink); | ||
formData.append("docs_url", data.docsRootUrl); | ||
formData.append("use_case", data.useCase); | ||
formData.append("source", data.source); | ||
|
||
const response = await submitGuruCreationForm(formData); | ||
|
||
if (response?.error) { | ||
throw new Error(response.message); | ||
} | ||
|
||
return response; | ||
} catch (error) { | ||
// console.error("Error submitting form:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
if (isSelfHosted) { | ||
redirect("not-found"); | ||
} | ||
|
||
return ( | ||
<HeaderFooterWrap> | ||
<GuruForm | ||
source={source} | ||
onSubmit={handleFormSubmit} | ||
defaultEmail={userEmail} | ||
isLoading={isLoading} | ||
/> | ||
</HeaderFooterWrap> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.