Skip to content

Commit 3767df9

Browse files
authored
Revert "RR "Simplify chatgpt apps by auto redirect""" (#2123)
Reverts #2114
2 parents db85e7f + f609dc1 commit 3767df9

File tree

2 files changed

+371
-41
lines changed

2 files changed

+371
-41
lines changed

plugins/example/chatgpt/main.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,54 @@
2222
@router.get("/", response_class=HTMLResponse)
2323
async def chatgpt_page(request: Request, uid: str = ""):
2424
"""
25-
Renders a simple redirect page to ChatGPT with the UID
25+
Renders the simplified ChatGPT integration page with direct link to OmiGPT
26+
"""
27+
# Log the access for analytics
28+
if uid:
29+
logger.info(f"ChatGPT integration page accessed with UID: {uid}")
30+
else:
31+
logger.warning("ChatGPT integration page accessed without UID")
32+
33+
return templates.TemplateResponse(
34+
"chatgpt/index.html",
35+
{
36+
"request": request,
37+
"uid": uid,
38+
"page_title": "Connect Omi with ChatGPT"
39+
}
40+
)
41+
42+
@router.get("/redirect", response_class=RedirectResponse)
43+
async def redirect_to_chatgpt(uid: str = ""):
44+
"""
45+
Redirects to ChatGPT with UID as a URL parameter
2646
"""
2747
try:
2848
if not uid or uid.strip() == "":
29-
# If no UID is provided, log the error
30-
logger.warning("ChatGPT integration accessed without UID")
49+
# If no UID is provided, redirect to the main page with an error
50+
logger.warning("Redirect attempted without UID")
3151
return RedirectResponse(
32-
url="/", # Redirect to home page if no UID
52+
url="/chatgpt?error=missing_uid",
3353
status_code=302
3454
)
3555

36-
# Log the access for analytics
37-
logger.info(f"ChatGPT integration page accessed with UID: {uid}")
56+
# Log the redirect for analytics
57+
logger.info(f"Redirecting to ChatGPT with UID: {uid}")
58+
59+
# Encode the UID for URL safety
60+
from urllib.parse import quote
61+
encoded_uid = quote(uid.strip())
3862

39-
# Return the template with the UID
40-
return templates.TemplateResponse(
41-
"chatgpt/index.html",
42-
{
43-
"request": request,
44-
"uid": uid.strip(),
45-
"page_title": "Redirecting to Omi for ChatGPT"
46-
}
63+
# Redirect to ChatGPT with UID as a URL parameter
64+
chatgpt_url = f"https://chatgpt.com/g/g-67e2772d0af081919a5baddf4a12aacf-omi?uid={encoded_uid}"
65+
return RedirectResponse(
66+
url=chatgpt_url,
67+
status_code=302
4768
)
4869
except Exception as e:
4970
logger.error(f"Error in redirect: {str(e)}")
5071
return RedirectResponse(
51-
url="/", # Redirect to home page on error
72+
url="/chatgpt?error=redirect_failed",
5273
status_code=302
5374
)
5475

0 commit comments

Comments
 (0)