🎉 first commit

This commit is contained in:
LIlGG
2025-09-24 13:06:25 +08:00
commit 1f4fb103e9
409 changed files with 61222 additions and 0 deletions

44
app/routes/chat.$id.tsx Normal file
View File

@@ -0,0 +1,44 @@
import { data, type LoaderFunctionArgs, redirect } from '@remix-run/node';
import { getUser, requireAuth } from '~/lib/.server/auth';
import { getUserChatById } from '~/lib/.server/chat';
import { getChatDeployments } from '~/lib/.server/deployment';
import { default as IndexRoute } from './_index';
export async function loader(args: LoaderFunctionArgs) {
// 添加权限验证
const authResult = await requireAuth(args.request);
// 如果返回的是Response对象说明验证失败并已重定向
if (authResult instanceof Response) {
return authResult;
}
// 获取当前用户 id
const authContext = await getUser(args.request);
const userId = authContext.userInfo?.sub as string;
const { id } = args.params;
if (!id || !userId) {
return redirect('/');
}
const chat = await getUserChatById(id, userId);
if (!chat) {
return redirect('/');
}
const url = new URL(args.request.url);
const rewindTo = url.searchParams.get('rewindTo') || '';
if (rewindTo) {
chat.messages = chat.messages.slice(0, chat.messages.findIndex((message) => message.id === rewindTo) + 1);
}
const deployments = await getChatDeployments(id);
return data({
id: args.params.id,
chat,
user: authResult.userInfo,
deployments,
});
}
export default IndexRoute;