feat: v1 — persistent shell, model gateway, artifact improvements (#1462)
This commit is contained in:
parent
3651670fb9
commit
f9652b452a
161 changed files with 5166 additions and 8009 deletions
43
app/(chat)/api/messages/route.ts
Normal file
43
app/(chat)/api/messages/route.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { auth } from "@/app/(auth)/auth";
|
||||
import { getChatById, getMessagesByChatId } from "@/lib/db/queries";
|
||||
import { convertToUIMessages } from "@/lib/utils";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const chatId = searchParams.get("chatId");
|
||||
|
||||
if (!chatId) {
|
||||
return Response.json({ error: "chatId required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const [session, chat, messages] = await Promise.all([
|
||||
auth(),
|
||||
getChatById({ id: chatId }),
|
||||
getMessagesByChatId({ id: chatId }),
|
||||
]);
|
||||
|
||||
if (!chat) {
|
||||
return Response.json({
|
||||
messages: [],
|
||||
visibility: "private",
|
||||
userId: null,
|
||||
isReadonly: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
chat.visibility === "private" &&
|
||||
(!session?.user || session.user.id !== chat.userId)
|
||||
) {
|
||||
return Response.json({ error: "forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const isReadonly = !session?.user || session.user.id !== chat.userId;
|
||||
|
||||
return Response.json({
|
||||
messages: convertToUIMessages(messages),
|
||||
visibility: chat.visibility,
|
||||
userId: chat.userId,
|
||||
isReadonly,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue