Skip to content

An AI-powered search engine with a generative UI

Add getSharedChat and shareChat functions to chat.ts

Yoshiki Miurafe3baf6f77f6
diff --git a/lib/actions/chat.ts b/lib/actions/chat.ts
index d0cce474..9651a89b 100644
--- a/lib/actions/chat.ts
+++ b/lib/actions/chat.ts
@@ -71,4 +71,31 @@ export async function saveChat(chat: Chat, userId: string = 'anonymous') {
member: `chat:${chat.id}`
})
await pipeline.exec()
-}
\ No newline at end of file
+}
+
+export async function getSharedChat(id: string) {
+ const chat = await redis.hgetall<Chat>(`chat:${id}`)
+
+ if (!chat || !chat.sharePath) {
+ return null
+ }
+
+ return chat
+}
+
+export async function shareChat(id: string, userId: string = 'anonymous') {
+ const chat = await redis.hgetall<Chat>(`chat:${id}`)
+
+ if (!chat || chat.userId !== userId) {
+ return null
+ }
+
+ const payload = {
+ ...chat,
+ sharePath: `/share/${id}`
+ }
+
+ await redis.hmset(`chat:${id}`, payload)
+
+ return payload
+}