Improve sidebar, new chat, and share dialog (#190)

This commit is contained in:
Jared Palmer 2023-12-04 12:42:53 -05:00 committed by GitHub
parent 35e83dc87e
commit be90a40427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 598 additions and 217 deletions

View file

@ -75,7 +75,7 @@ export async function clearChats() {
const chats: string[] = await kv.zrange(`user:chat:${session.user.id}`, 0, -1)
if (!chats.length) {
return redirect('/')
return redirect('/')
}
const pipeline = kv.pipeline()
@ -100,15 +100,23 @@ export async function getSharedChat(id: string) {
return chat
}
export async function shareChat(chat: Chat) {
export async function shareChat(id: string) {
const session = await auth()
if (!session?.user?.id || session.user.id !== chat.userId) {
if (!session?.user?.id) {
return {
error: 'Unauthorized'
}
}
const chat = await kv.hgetall<Chat>(`chat:${id}`)
if (!chat || chat.userId !== session.user.id) {
return {
error: 'Something went wrong'
}
}
const payload = {
...chat,
sharePath: `/share/${chat.id}`