|
22 | 22 | @router.get("/", response_class=HTMLResponse) |
23 | 23 | async def chatgpt_page(request: Request, uid: str = ""): |
24 | 24 | """ |
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 |
26 | 46 | """ |
27 | 47 | try: |
28 | 48 | 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") |
31 | 51 | return RedirectResponse( |
32 | | - url="/", # Redirect to home page if no UID |
| 52 | + url="/chatgpt?error=missing_uid", |
33 | 53 | status_code=302 |
34 | 54 | ) |
35 | 55 |
|
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()) |
38 | 62 |
|
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 |
47 | 68 | ) |
48 | 69 | except Exception as e: |
49 | 70 | logger.error(f"Error in redirect: {str(e)}") |
50 | 71 | return RedirectResponse( |
51 | | - url="/", # Redirect to home page on error |
| 72 | + url="/chatgpt?error=redirect_failed", |
52 | 73 | status_code=302 |
53 | 74 | ) |
54 | 75 |
|
|
0 commit comments