-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: pre launch merge conflict #347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,71 +1,39 @@ | ||||||||||||
//import { ImageResponse } from '@vercel/og' | ||||||||||||
// generates the image with error ↑ | ||||||||||||
import { ImageResponse } from 'next/og' | ||||||||||||
import { NextRequest } from 'next/server' | ||||||||||||
import { getThreadForOG } from './edge-client' | ||||||||||||
import { getThread } from '@/services/hasura' | ||||||||||||
import '@/app/globals.css' | ||||||||||||
import OGImage from '@/components/shared/og-image' | ||||||||||||
import { UUID } from '@/types/types' | ||||||||||||
export const runtime = 'edge' | ||||||||||||
|
||||||||||||
const defaultContent = { | ||||||||||||
thread: { | ||||||||||||
chatbot: { | ||||||||||||
name: 'Masterbots', | ||||||||||||
avatar: process.env.NEXT_PUBLIC_BASE_URL + '/images/masterbots.png', | ||||||||||||
categories: [{ category: { name: 'AI' } }] | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
question: | ||||||||||||
'Elevating AI Beyond ChatGPT: Specialized Chatbots, Social Sharing and User-Friendly Innovation', | ||||||||||||
answer: | ||||||||||||
'Elevating AI Beyond ChatGPT: Specialized Chatbots, Social Sharing and User-Friendly Innovation', | ||||||||||||
username: 'Masterbots', | ||||||||||||
user_avatar: process.env.NEXT_PUBLIC_BASE_URL + '/images/masterbots.png', | ||||||||||||
isLightTheme: false | ||||||||||||
} | ||||||||||||
// export const runtime = 'edge' | ||||||||||||
|
||||||||||||
export async function GET(req: NextRequest) { | ||||||||||||
try { | ||||||||||||
const { searchParams } = req.nextUrl | ||||||||||||
const rawThreadId = searchParams.get('threadId') | ||||||||||||
const threadId = rawThreadId?.match(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) | ||||||||||||
? (rawThreadId as UUID) | ||||||||||||
: null | ||||||||||||
|
||||||||||||
if (!threadId) { | ||||||||||||
return new ImageResponse(<OGImage {...defaultContent} />, { | ||||||||||||
width: 1200, | ||||||||||||
height: 627 | ||||||||||||
}) | ||||||||||||
} | ||||||||||||
const thread = await getThreadForOG(threadId) | ||||||||||||
|
||||||||||||
if (!thread?.thread?.length) { | ||||||||||||
// Use metadata when thread not found | ||||||||||||
return new ImageResponse(<OGImage {...defaultContent} />, { | ||||||||||||
width: 1200, | ||||||||||||
height: 627 | ||||||||||||
}) | ||||||||||||
} | ||||||||||||
|
||||||||||||
const threadData = thread.thread[0] | ||||||||||||
const threadId = searchParams.get('threadId') | ||||||||||||
const thread = await getThread({ threadId, jwt: '' }) | ||||||||||||
const question = | ||||||||||||
threadData?.messages?.find((m: { role: string }) => m.role === 'user') | ||||||||||||
?.content || 'not found' | ||||||||||||
thread.messages.find(m => m.role === 'user')?.content || 'not found' | ||||||||||||
const answer = | ||||||||||||
threadData?.messages?.find( | ||||||||||||
(m: { role: string }) => m.role === 'assistant' | ||||||||||||
)?.content || 'not found' | ||||||||||||
const username = threadData?.user?.username || 'Anonymous' | ||||||||||||
const user_avatar = threadData?.user?.profilePicture || '' | ||||||||||||
thread.messages.find(m => m.role === 'assistant')?.content || 'not found' | ||||||||||||
const username = thread.user?.username | ||||||||||||
const user_avatar = thread.user?.profilePicture || '' | ||||||||||||
|
||||||||||||
let theme = 'dark' | ||||||||||||
if (typeof window !== 'undefined') { | ||||||||||||
theme = localStorage.getItem('theme') || 'dark' | ||||||||||||
} | ||||||||||||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using
Apply this diff to remove browser-specific code: let theme = 'dark'
-if (typeof window !== 'undefined') {
- theme = localStorage.getItem('theme') || 'dark'
-}
const isLightTheme = theme === 'light' If you need to determine the theme based on the request, consider passing it as a query parameter: const threadId = searchParams.get('threadId')
+const theme = searchParams.get('theme') || 'dark'
const thread = await getThread({ threadId, jwt: '' })
// ...
const isLightTheme = theme === 'light' 📝 Committable suggestion
Suggested change
|
||||||||||||
const isLightTheme = theme === 'light' | ||||||||||||
return new ImageResponse( | ||||||||||||
( | ||||||||||||
<OGImage | ||||||||||||
thread={threadData} | ||||||||||||
thread={thread} | ||||||||||||
question={question} | ||||||||||||
answer={answer} | ||||||||||||
username={username} | ||||||||||||
user_avatar={user_avatar} | ||||||||||||
isLightTheme={false} | ||||||||||||
isLightTheme={isLightTheme} | ||||||||||||
/> | ||||||||||||
), | ||||||||||||
{ | ||||||||||||
|
@@ -74,9 +42,12 @@ export async function GET(req: NextRequest) { | |||||||||||
} | ||||||||||||
) | ||||||||||||
} catch (e: any) { | ||||||||||||
console.error('OG Image generation error:', e) | ||||||||||||
return new Response(`Failed to generate the image: ${e.message}`, { | ||||||||||||
console.log(`${e.message}`) | ||||||||||||
return new Response(`Failed to generate the image`, { | ||||||||||||
status: 500 | ||||||||||||
}) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
function useTheme() { | ||||||||||||
throw new Error('Function not implemented.') | ||||||||||||
} | ||||||||||||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused The Apply this diff to remove the unused function: -function useTheme() {
- throw new Error('Function not implemented.')
-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate
threadId
before using itThe
threadId
retrieved fromsearchParams.get('threadId')
might benull
or invalid. Consider adding validation to ensurethreadId
is present and correctly formatted before using it ingetThread
. This will prevent potential runtime errors or security issues.Apply this diff to add validation:
📝 Committable suggestion